简体   繁体   English

使用NUnit需要哪些步骤?

[英]What are the Steps needed to use NUnit?

I Developed a small Application in C#. 我用C#开发了一个小应用程序。 I want to test my application with NUnit.I am a new to NUnit.I Installed NUnit but don't Know How to use it what are the basic steps needed for it or please provide me a good reference link about using NUnit. 我想用NUnit测试我的应用程序。我是NUnit.I的新手。安装了NUnit但不知道如何使用它需要的基本步骤或者请给我一个关于使用NUnit的良好参考链接。

Check out the NUnit quick start : 查看NUnit快速入门

Let's start with a simple example. 让我们从一个简单的例子开始。 Suppose we are writing a bank application and we have a basic domain class – Account. 假设我们正在编写银行应用程序,并且我们有一个基本的域类 - 帐户。 Account supports operations to deposit, withdraw, and transfer funds. 账户支持存入,取出和转移资金的操作。

I recommend you to have an own project for your tests (like Project.Tests ). 我建议你有一个自己的测试项目(比如Project.Tests )。

Place the following basic files somewhere in folder of your project structure (eg lib\\nunit\\nunit ): 将以下基本文件放在项目结构的文件夹中(例如lib\\nunit\\nunit ):

  • nunit.core.dll
  • nunit.core.interfaces.dll
  • nunit.framework.dll
  • nunit.util.dll
  • nunit-console.exe
  • nunit-console.exe.config
  • nunit-console-runner.dll
  • nunit-console-x86.exe
  • nunit-console-x86.exe.config

Then you need to reference the NUnit.Framework assembly in your Project.Tests project. 然后,您需要在Project.Tests项目中引用NUnit.Framework程序集。

For example, a simple test would look like this: 例如,一个简单的测试看起来像这样:

using NUnit.Framework;

namespace Project.Tests
{
    [TestFixture]
    public class MyTestClass
    {
        [Test]
        public void MyTestMethod()
        {
            var a = "a";
            var b = "a";
            Assert.AreEqual(a, b);
        }
    }
}

You can run this test then for example with the NUnit-console or directly in VisualStudio (eg with the help of ReSharper ) or through a MSBuild task with the help of MSBuild Community Tasks . 您可以运行此测试,例如使用NUnit控制台或直接在VisualStudio中(例如在ReSharper的帮助下)或在MSBuild社区任务的帮助下通过MSBuild任务运行

如果你不使用resharper,我建议你使用这个插件 - http://www.testdriven.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM