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
87
votes
5 answers

CollectionAssert in jUnit?

Is there a jUnit parallel to NUnit's CollectionAssert?
ripper234
  • 222,824
  • 274
  • 634
  • 905
85
votes
6 answers

NUnit parameterized tests with datetime

Is it not possible with NUnit to go the following? [TestCase(new DateTime(2010,7,8), true)] public void My Test(DateTime startdate, bool expectedResult) { ... } I really want to put a datetime in there, but it doesn't seem to like it. The error…
AnonyMouse
  • 18,108
  • 26
  • 79
  • 131
82
votes
2 answers

NUnit.Framework.Assert.IsInstanceOfType() is obsolete

I'm currently reading the book Professional Enterprise .NET and I've noticed this warning in some of the example programs: 'NUnit.Framework.Assert.IsInstanceOfType(System.Type, object)' is obsolete Now I may have already answered my own question…
Malice
  • 3,927
  • 1
  • 36
  • 52
82
votes
10 answers

When do I use the TestFixtureSetUp attribute instead of a default constructor?

The NUnit documentation doesn't tell me when to use a method with a TestFixtureSetup and when to do the setup in the constructor. public class MyTest { private MyClass myClass; public MyTest() { myClass = new MyClass(); } …
Paco
  • 8,335
  • 3
  • 30
  • 41
82
votes
5 answers

How do I test an async method with NUnit (or possibly with another framework)?

I have an ASP.NET Web API application, with an ApiController that features asynchronous methods, returning Task<> objects and marked with the async keyword. public class MyApiController : ApiController { public async Task
aknuds1
  • 65,625
  • 67
  • 195
  • 317
81
votes
22 answers

HRESULT: 0x80131040: The located assembly's manifest definition does not match the assembly reference

The located assembly's manifest definition does not match the assembly reference getting this when running nunit through ncover. Any idea?
chethan
80
votes
10 answers

Using Moq to verify calls are made in the correct order

I need to test the following method: CreateOutput(IWriter writer) { writer.Write(type); writer.Write(id); writer.Write(sender); // many more Write()s... } I've created a Moq'd IWriter and I want to ensure that the Write() methods…
g t
  • 7,287
  • 7
  • 50
  • 85
78
votes
5 answers

How to run Google Chrome with Selenium RC?

I am trying to test my site with Selenium RC + Nunit + asp.net. I can get my tests to work in Firefox,Safari,opera,IE 8 but not google chrome. I put this in for the browser arugment selenium = new DefaultSelenium(Server, ServerPort, …
chobo2
  • 83,322
  • 195
  • 530
  • 832
76
votes
4 answers

How can I pass dynamic objects into an NUnit TestCase function?

I am writing a data-intensive application. I have the following tests. They work, but they're pretty redundant. [Test] public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InMerchantAggregateTotals_SetsWarning() { …
Alexander Garden
  • 4,468
  • 3
  • 31
  • 25
75
votes
6 answers

MSTest Equivalent for NUnit's Parameterized Tests?

NUnit supports a feature where you can specify a set of data inputs for a unit test to be run multiple times. [RowTest] [Row(1001,1,2,3)] [Row(1,1001,2,3)] [Row(1,2,1001,3)] public void SumTests(int x, int y, int z, int expected) { ... } What's…
blaster
  • 8,876
  • 11
  • 48
  • 77
74
votes
2 answers

Using Verify to confirm expected parameter values in Moq mock class

I'm trying to verify that a method within a mock is called with an expected object parameter. I'm using Moq, nUnit, and thinking that AutoFixture's Likeness should get the job done. Below is a simplified version of what i'm trying to do. Is there…
jaminto
  • 3,895
  • 3
  • 32
  • 36
74
votes
3 answers

NUnit Assert.AreEqual DateTime Tolerances

I'm wondering if anybody's found a good solution to this: In our unit tests; we commonly use Assert.AreEqual() to validate our results. All is well and good; until we start trying to use this on DateTime properties. Although the times are very…
Jim B
  • 8,344
  • 10
  • 49
  • 77
73
votes
6 answers

Unit Testing File I/O

Reading through the existing unit testing related threads here on Stack Overflow, I couldn't find one with a clear answer about how to unit test file I/O operations. I have only recently started looking into unit testing, having been previously…
Shaun Hamman
  • 2,287
  • 4
  • 21
  • 33
72
votes
9 answers

NUnit TestCase with Generics

Is there any way to pass generic types using a TestCase to a test in NUnit? This is what I would like to do but the syntax is not correct... [Test] [TestCase] public void…
Russell Giddings
  • 8,731
  • 5
  • 34
  • 35
71
votes
5 answers

How can I convert Assembly.CodeBase into a filesystem path in C#?

I have a project that stores templates in a \Templates folder next to the DLLs and EXE. I want to determine this file path at runtime, but using a technique that will work inside a unit test as well as in production (and I don't want to disable…
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197