NUnit测试问题 [英] NUnit Test problem

查看:83
本文介绍了NUnit测试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在运行此nunit时安装了Nunit,它给了我一些错误,而我得到的错误是此程序集不是使用任何已知的测试框架构建的" ,在c#中,我正在添加.net框架,因为我没有获取.dll文件,我什至没有浏览器尝试从程序文件中放入文件,但它没有在参考文件夹中显示我,请让我知道在这种情况下我该怎么做?

当我编写此代码时:

Hi
I have install Nunit when i am running this nunit it gives me some error and the error i am getting is "This assembly was not built with any known testing framework" and in c# in reference i am adding the .net framework and in that i am not getting .dll file i have even browser an try to put from program files but it is not showing me in reference folder please let me know what i do in this case?

When i am writing this code:

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
        }

        public float balance;

        public void Deposite(float amount)
        {
            balance += amount;
        }

        public void withdraw(float amount)
        {
            balance -= amount;
        }

        public void TransferFunds(Program destination, float amount)
        {
        }

        public float Balance
        {
            get { return balance; }
        }

        public static void testmethod()
        {
            Program a1 = new Program();
            a1.Deposite(200.00f);
            Program a2 = new Program();
            a2.Deposite(15.00f);
            a1.TransferFunds(a2, 100.00f);
            Program.Equals(250.00f, a2.balance);
            Program.Equals(100.00f, a1.balance);
        }
    }

    [TestFixture()]
    public class Calculator_UnitTest
    {
        Program a1 = new Program();

        [SetUp()]
        public void Init()
        {
            // some code here, that need to be run
            // at the start of every test case.
        }

        [TearDown()]
        public void Clean()
        {
            // code that will be called after each Test case
        }

        [Test]
        public void Test()
        {
            Program a1 = new Program();
            a1.Deposite(200.00f);
            Program a2 = new Program();
            a2.Deposite(15.00f);
            a1.TransferFunds(a2, 100.00f);
            Program.Equals(250.00f, a2.balance);
            Program.Equals(100.00f, a1.balance);
       }
   }
}


它不支持NUnit.Framework[TestFixture()] all ,请提供帮助.


It''s not supporting NUnit.Framework nor [TestFixture()] and all please help.

推荐答案

尝试拆分程序* project *从测试项目. IE.在您的解决方案中创建两个项目:一个带有生产代码(例如,控制台应用程序程序集或lib程序集),另一个带有测试程序集(一个lib程序集).测试程序集应引用生产程序集,并且测试代码应调用生产程序集的待测试方法.

还要检查项目的属性.生成选项卡(例如在VS2010中)应显示某些受支持的Framework版本,例如.Net Framework 4.

干杯

安迪
Try to split the program *project* from the test project. I.e. make two projects in your solution: one with the productive code (e.g. a console app assembly or a lib assembly) and one with the test assembly (a lib assembly). The test assembly should reference the productive assembly and the test code should call the to-be-tested methods of the productive assembly.

Check also the properties of your project(s). The build tab (e.g. in VS2010) should show some supported Framework version, e.g. .Net Framework 4.

Cheers

Andi


这篇关于NUnit测试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆