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
142
votes
21 answers

Determine if code is running as part of a unit test

I have a unit test (nUnit). Many layers down the call stack a method will fail if it is running via a unit test. Ideally you would use something like mocking to setup the object that this method is depending on but this is 3rd party code and I can't…
Ryan
  • 23,871
  • 24
  • 86
  • 132
142
votes
2 answers

NUnit's Assert.Equals throws exception "Assert.Equals should not be used for assertions"

I recently attempted to use the method Assert.Equals() when writing a new NUnit test. Upon execution this method throws an AssertionException stating that Assert.Equals should not be used for Assertions. This is a bit baffling at first glance. …
Odrade
  • 7,409
  • 11
  • 42
  • 65
139
votes
6 answers

Test parameterization in xUnit.net similar to NUnit

Are there any means in xUnit.net framework similar to the following features of NUnit? [Test, TestCaseSource("CurrencySamples")] public void Format_Currency(decimal value, string expected){} static object[][] CurrencySamples = new object[][] { …
UserControl
  • 14,766
  • 20
  • 100
  • 187
134
votes
16 answers

NUnit Test Run Order

By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?
Riain McAtamney
  • 6,342
  • 17
  • 49
  • 62
123
votes
13 answers

How do you test private methods with NUnit?

I am wondering how to use NUnit correctly. First, I created a separate test project that uses my main project as reference. But in that case, I am not able to test private methods. My guess was that I need to include my test code into my main code?!…
MrFox
  • 3,233
  • 6
  • 25
  • 27
120
votes
19 answers

How do I run NUnit in debug mode from Visual Studio?

I've recently been building a test framework for a bit of C# I've been working on. I have NUnit set up and a new project within my workspace to test the component. All works well if I load up my unit tests from Nunit (v2.4), but I've got to the…
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
119
votes
9 answers

Unit test, NUnit or Visual studio?

I'm using Visual studio (sometimes resharper) to run my unit test. I heard about NUnit, but I don't know many things about it... Should I care about it ? Can it offer something better than visual studio? Should I Use NUnit and why?
Tim
  • 2,887
  • 10
  • 33
  • 33
116
votes
3 answers

Moq: Invalid setup on a non-overridable member: x => x.GetByTitle("asdf")

Not sure how I can fix this, trying to do a unit test on the method "GetByTitle" Here are my definitions: public class ArticleDAO : GenericNHibernateDAO(IArticle, int>, IArticleDAO { public IArticle GetByTitle(string title) { IQuery…
mrblah
  • 99,669
  • 140
  • 310
  • 420
109
votes
21 answers

Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds

I've been using Selenium for a number of months, which we're using to automate some of our internal testing processes. The scripts have been passing fine. I've recently upgraded to C# 2.40.0 webdriver using FF 27.01 and our scripts are now failing…
Nathan
  • 1,099
  • 2
  • 7
  • 4
107
votes
3 answers

The current SynchronizationContext may not be used as a TaskScheduler

I am using Tasks to run long running server calls in my ViewModel and the results are marshalled back on Dispatcher using TaskScheduler.FromSyncronizationContext(). For example: var context =…
anivas
  • 6,437
  • 6
  • 37
  • 45
98
votes
10 answers

NUnit isn't running Visual Studio 2010 code

I'm trying to load a Visual Studio 2010 beta dll into the NUnit GUI. I get a popup error. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. You may be attempting to load an assembly build with a…
Ball
  • 2,591
  • 3
  • 19
  • 26
96
votes
2 answers

ReSharper Error: "The output has reached the limit and was truncated. To view the full output use 'Show Stack Trace in a new window' action."

When running unit tests in ReSharper, if the output is too long, it gives this error: The output has reached the limit and was truncated. To view the full output use 'Show Stack Trace in a new window' action. Update ReSharper fixed this issue in…
Contango
  • 76,540
  • 58
  • 260
  • 305
95
votes
5 answers

Testing for exceptions in async methods

I'm a bit stuck with this code (this is a sample): public async Task Fail() { await Task.Run(() => { throw new Exception(); }); } [Test] public async Task TestFail() { Action a = async () => { await Fail(); }; …
Eugene
  • 1,073
  • 1
  • 7
  • 7
87
votes
7 answers

Test with NO expected exception

I want to create NUnit test to ensure that my function does not throw an exception. Is there some specific way to do it, or I should just write [Test] public void noExceptionTest() { testedFunction(); } and it will succeed if no exception is…
Yury Pogrebnyak
  • 4,093
  • 9
  • 45
  • 78
87
votes
13 answers

How can I run NUnit tests in parallel?

I've got a large acceptance test (~10 seconds per test) test suite written using NUnit. I would like to make use of the fact that my machines are all multiple core boxes. Ideally, I'd be able to have one test running per core, independently of other…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552