TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no tests are coupled. If you want to run methods before and after ALL tests, decorate relevant methods with the ClassInitialize and ClassCleanup attributes.
Each NUnit test runs in an execution context, which includes information about the environment as well as the test itself. The TestContext class allows tests to access certain information about the execution context.
You have to add reference to
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
It can be found at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\
directory (for VS2010 professional or above; .NET Framework 4.0).
or right click on your project and select: Add Reference... > .NET:
I know this is old, this is what came up in my Google search. I needed to reference these packages on NuGet:
The DLL you're looking for that contains that namespace is
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Note that unit testing cannot be used in Visual Studio Express.
To resolve this issue, I had to do the following:
Once the DLLs are installed, you can add references to them using the method that Agent007 indicated in his answer.
There is also a nice nuget package. It will pull the dll to your packages folder. You will need to add the reference to the dll manually.
NOTE: This package is not an official Microsoft package.
If you are using Visual Studio 2017 Community, the location is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\v2.0
The DLL you want is there: Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Apparently it is located in the C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\
directory for Visual Studio 2010 Professional version, but take note that the 10.0
will change to correspond with the release year, i.e. VS 2013 was version 12.0, VS 2015 was version 14.0, VS 2017 is 15.0. (VS Express is not supported and would require installing the NUnit NuGet package, through the NuGet Package Manager, instead.)
You go to References, right-click, select Add Reference, Browse. Navigate to the path, then double-click the file.
Then, you need a using
statement at the top of your Unit Test class:
using Microsoft.VisualStudio.TestTools.UnitTesting;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With