简体   繁体   中英

What are the Steps needed to use NUnit?

I Developed a small Application in 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.

Check out the NUnit quick start :

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 ).

Place the following basic files somewhere in folder of your project structure (eg 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.

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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