Questions tagged [nunit]

NUnit is an open source unit testing framework for .NET and Silverlight written in C#. It serves the same purpose as JUnit or TestNG does in the Java world, and is one of many in the xUnit family.

Initially ported from JUnit, this xUnit based unit testing tool for was written entirely in and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. NUnit brings xUnit to all .NET languages. The current production release, version 3, has been completely rewritten with many new features and support for a wide range of .NET platforms.

References

Tutorials

7425 questions
49
votes
3 answers

.NET unit testing projects organisation

What would you say is the best way to manage the unit tests in a large .net application? Is it better to add a test project for each separate project in the solution or one large tests project for all the tests in the rest of the projects? For…
alxbrd
  • 1,675
  • 1
  • 15
  • 16
48
votes
3 answers

Running NUnit through Resharper 8 tests fail when crossing between projects due to AppDomain

I recently updated to Resharper 8, and when I tried to run a suite of projects. These tests contain two suites of integration tests that both use IISExpress to run a website, make web requests and check the responses. Running them in isolation is…
hawx
  • 1,313
  • 12
  • 10
48
votes
10 answers

Resharper runs UnitTest from different location

When I run unit tests with Visual Studio it works fine, because it runs from project directory where all assemblies are. But when I run it with resharper it goes with error on var services = Assembly.Load("SomeAssembly"); with error Could not…
Roar
  • 2,117
  • 4
  • 24
  • 39
48
votes
5 answers

Visual Studio 2012 MSTest vs NUnit pros and cons

We have to decide which technology to use for our unit testing. Currently we use Visual Studio 2010 and not happy with MSTest that came with that. It is buggy, poor in deployment (E.g the test setting output directory is not recognized correctly),…
Sriwantha Attanayake
  • 7,694
  • 5
  • 42
  • 44
48
votes
2 answers

How can I add log messages to an NUnit test that will appear in a nant build execution?

With NUnit, if you add Debug.Print statements in your tests they appear in the test output. (At least they do in the ReSharper unit test window.) When using a NAnt build file that executes the same tests, those Debug.Print statements do not…
The Evil Greebo
  • 7,013
  • 3
  • 28
  • 55
48
votes
2 answers

Differences between Assert.True and Assert.IsTrue in NUnit?

Is there any differences between those two?
Vlad Titov
  • 686
  • 1
  • 6
  • 15
48
votes
8 answers

Unit Testing ASP.net Web Site Project code stored in App_Code

I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code behind code files (including Linq2Sql stuff, data contexts, business logic, extension methods, etc) are located in the App_Code folder. I am interested in introducing Unit…
Yaakov Ellis
  • 40,752
  • 27
  • 129
  • 174
47
votes
3 answers

Using Moq to mock a repository that returns IQueryable

How to I setup my Moq to return some values and having the tested service select the right one? IRepository: public interface IGeographicRepository { IQueryable GetCountries(); } Service: public Country GetCountry(int countryId) { …
Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406
47
votes
4 answers

How to access the NUnit test name programmatically?

Is there some global state somewhere that I can access the currently-running test name? I have tests which output files into a directory and read them back in. I'd like each test to create a directory to play in and then clean up after itself, and I…
TALlama
  • 16,017
  • 8
  • 38
  • 47
47
votes
3 answers

where did NUnit Gui Runner go? version 3.0.1

I just upgraded to version 3.0.1 from nunit 2.6.4. It used to have a NUnit Gui Runner, located here: After installing 3.0.1 (which I downloaded windows version from here) I now no longer see the nunit.exe in the installation folder, for example the…
sapbucket
  • 6,795
  • 15
  • 57
  • 94
47
votes
2 answers

nUnit Assert.That(method,Throws.Exception) not catching exceptions

Can someone tell me why this unit test that checks for exceptions fails? Obviously my real test is checking other code but I'm using Int32.Parse to show the issue. [Test] public void MyTest() { Assert.That(Int32.Parse("abc"),…
Jason More
  • 6,983
  • 6
  • 43
  • 52
45
votes
2 answers

Testing for exceptions with [TestCase] attribute in NUnit 3?

How do I test for exceptions in a TestCase with NUnit3? Let's say I have a method Divide(a,b) defined as follows: public double Divide(double a, double b) { if(Math.Abs(b) < double.Epsilon) throw new ArgumentException("Divider cannot be 0"); …
Corpus Gigantus
  • 585
  • 1
  • 4
  • 7
45
votes
4 answers

Assert.That vs Assert.True

What to prefer: Assert.That(obj.Foo, Is.EqualTo(true)) or Assert.True(obj.Foo) For me, both asserts are equivalent, so which one should be prefered?
Razer
  • 7,843
  • 16
  • 55
  • 103
44
votes
2 answers

.NET NUnit test - Assembly.GetEntryAssembly() is null

When class used Assembly.GetEntryAssembly() run in unit test, the Assembly.GetEntryAssembly() is null. Is there some option how define Assembly.GetEntryAssembly() during unit testing?
Simon
  • 3,235
  • 5
  • 36
  • 47
44
votes
5 answers

NUnit global initialization - bad idea?

We need some global one time setup code in our test suite. We can do it more than once but it takes quite some time. It's required by all fixtures so [TestFixtureSetUp] does not work. It has to run before all [TestFixtureSetUp] code. Put it in…
Sedat Kapanoglu
  • 46,641
  • 25
  • 114
  • 148