Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013/2015 Test Project Template - for NUnit?

I'm new to unit testing and started with MSTest and want to use NUnit. I see there is a Test project template in VS 2015 but I read that for NUnit I'm to create a class library then add the NUnit NuGet packages.

What is correct? Test Project Template or Class Library for NUnit in C#?

Thank you

like image 416
Neal Avatar asked Mar 15 '23 07:03

Neal


1 Answers

There is no NUnit test project template in Visual Stusio that comes out of the box.

A test project is a class library with a reference to nunit.framework.dll that comes with NUnit installation.

You can create your own NUnit project template in Visual Studio:

  1. Creating a new class library
  2. Reference nunit.framework.dll
  3. Create test.cs file
    • Add "using NUnit.Framework;"
    • Create an empty test class and a test method (you can also add setup and teardown to the test class)

Your Test.cs File should look something like this:

using System;
using NUnit.Framework;

namespace NUnit.Tests
{
  [TestFixture]
  public class SuccessTests
  {
    [SetUp] public void Init()
    { /* ... */ }

    [TearDown] public void Dispose()
    { /* ... */ }

    [Test] public void Test1()
    { /* ... */ }
  }
}
  1. Use Export Template wizard to create a template out of your project.
like image 62
Al.exe Avatar answered Apr 02 '23 08:04

Al.exe