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
61
votes
13 answers

Unit testing the app.config file with NUnit

When you guys are unit testing an application that relies on values from an app.config file? How do you test that those values are read in correctly and how your program reacts to incorrect values entered into a config file? It would be ridiculous…
Dana
  • 32,083
  • 17
  • 62
  • 73
60
votes
3 answers

Grabbing the output sent to Console.Out from within a unit test?

I am building a unit test in C# with NUnit, and I'd like to test that the main program actually outputs the right output depending on the command line arguments. Is there a way from an NUnit test method that calls Program.Main(...) to grab…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
59
votes
2 answers

xUnit or NUnit? What advantages and disadvantages of each other?

What are the pluses and minuses of each framework, comparing to each other? How well they work with ASP.NET MVC? How well they support mocking?
Dmitry
  • 789
  • 2
  • 6
  • 7
57
votes
8 answers

FluentAssertions: equivalence of sorted lists

I'm trying to establish equivalence of two lists using FluentAssertions in C#, where two things are of importance: the elements are compared by the values they hold, not by reference (i.e. they are equivalent, not equal) the order of the elements…
Samuel Neugber
  • 1,041
  • 1
  • 11
  • 17
55
votes
10 answers

.NET testing framework advice

I'm looking to introduce a unit testing framework into the mix at my job. We're using Visual Studio 2005 (though we may be moving to 2008 within the next six months) and work primarily in C#. If the framework has some kind of IDE integration that…
saalon
  • 3,644
  • 3
  • 33
  • 40
54
votes
2 answers

How to use Fluent Assertions to test for exception in inequality tests?

I'm trying to write a unit test for a greater than overridden operator using Fluent Assertions in C#. The greater than operator in this class is supposed to throw an exception if either of the objects are null. Usually when using Fluent Assertions,…
Nathan Bierema
  • 1,813
  • 2
  • 14
  • 24
54
votes
8 answers

How do I put new List {1} in an NUNIT TestCase?

I have the method: public static int Add(List numbers) { if (numbers == null || numbers.Count == 0) return 0; if (numbers.Count == 1) return numbers[0]; throw new…
xaisoft
  • 3,343
  • 8
  • 44
  • 72
54
votes
2 answers

Moq fake one method but use real implementation of another

Given an interface IService that has Method1() and Method2(). I want to test that when Method1() throws an Exception, Method2() is called and returns a given value. (Method2() is called when Method1() throws). Therefore I need to test a real…
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
52
votes
7 answers

Is it possible to parameterize a nunit test

I would like to write a callable function that accepts two objects, and compares 30+ properties of those objects with asserts. The issue is this needs to be done for about 20 existing unit tests and most future tests, and writing out the 30+ asserts…
NewNetProgrammer
  • 523
  • 1
  • 4
  • 4
52
votes
6 answers

Nunit async test exception assertion

[Edit (May 2020)] - This issue has been reportedly addressed in newer releases of NUnit. Please see Nunit.ThrowsAsync. (Ref this answer, thanks @James-Ross) I have a controller UserController with this action // GET /blah public Task
Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
51
votes
9 answers

Is there a free Visual Studio addin for Nunit?

I'm cheap and don't want to pay for ReSharper or TestDriven.NET, is there a free visual Studio addin for NUnit?
Eric Labashosky
  • 29,484
  • 14
  • 39
  • 32
50
votes
3 answers

MVC 3: How to learn how to test with NUnit, Ninject, and Moq?

Short version of my questions: Can anyone point me toward some good, detailed sources from which I can learn how to implement testing in my MVC 3 application, using NUnit, Ninject 2, and Moq? Can anyone here help clarify for me how…
campbelt
  • 1,573
  • 5
  • 27
  • 43
50
votes
2 answers

Programmatically skip an NUnit test

Is there a way for an NUnit test to end and tell the test runner that it should be considered skipped/ignored, rather than succeeded or failed? My motivation for this is that I have a few tests that don't apply in certain circumstances, but this…
Andy Johnson
  • 7,938
  • 4
  • 33
  • 50
50
votes
3 answers

Using WPF components in NUnit tests - how to use STA?

I need to use some WPF components in an NUnit unit test. I run the test through ReSharper, and it fails with the following error when using the WPF object: System.InvalidOperationException: The calling thread must be STA, because many UI components…
stiank81
  • 25,418
  • 43
  • 131
  • 202
49
votes
2 answers

NUnit and [SetUp] in base classes

I'm looking at some test code using NUnit, which inherits from a base class containing a [SetUp] attribute: public class BaseClass { [SetUp] public void SetUp() { //do something } } [TestFixture] public class DerivedClass :…
larryq
  • 15,713
  • 38
  • 121
  • 190