NUnit 3 recently released and if you’ve picked it up you’ve probably already found that there are several changes between version 3 and version 2.
If you haven’t, here are some highlights:
This is probably the most anticipated change. We can finally run multiple tests at the same time.
In NUnit 3.0, we finally have the ability to run multiple tests at the same time by using the
Parallelizable Attribute in combination with the
By default, all of our tests run sequentially. But if you’ve written your tests correctly, you should be able to run them all at the same time. To enable this feature, you’ll need to first specify how many tests you can run at the same time by adding the
LevelOfParallelism attribute to your assembly.
properties/AssemblyInfo.cs file add the following code:
To make a test run at the same time as other tests, add the
Parallelizable attribute to either the namespace, or class. As of NUnit 3.0, running tests within a fixture in parallel is not yet supported.
The Parallelizable attribute takes one optional parameter named
ParallelScope. This option allows you to specify what level of code can run in parallel.
- None: No tests can run in parallel
- Self: This level can run in parallel with other similar levels
- Children: Test under this level can run in parallel.
- Fixtures: Only fixtures under this level can run in parallel.
Attributes applied to nested namespaces or classes override attributes applied to namespaces they are within.
Another big change is the test runner. By default, the test runner is just a regular console app. I don’t know about you, but I miss the tree view. But it is what it is.
I would suggest that you invest in ReSharper just to get the test runner that it has. If you can’t do that, use the MS Test Adapter from NUnit.org to run your tests in Visual Studio using the MS Test Runner.
In NUnit 2, we had the option of using the
ExpectedException attribute on a test that was supposed to throw an exception or we could use the
Assert.That syntax that we’ve already documented. In NUnit 3,
ExpectedException is no longer available.
In NUnit 2, when we wanted to have a method that only ran once for a test class as part of setup or teardown, we would use these two attributes. We would also use these in combination with the
SetupFixture attribute to run methods once at the namespace level.
In NUnit 3, these have been replaced with
OneTimeTearDown in both cases.
TestFixtureTearDown will continue to work as part of a
TestFixture, you should move to the new attributes as soon as possible.
If you specify the property to use for your tests data using a string, that property now HAS to be static.
Similarly, this now only uses a static property when specified as a string.
Several assert syntaxes have changed. Once again, check the documentation.
What significant changes have you noticed? Let me know in the comments.
Other post in Testing
- Selenium with NUnit Presentation - February 17th, 2014
- “Debbie-Done” - March 4th, 2014
- When You Really Need All Of Your NUnit Test In One Class - March 18th, 2014
- TDD Isn’t All About Testing - March 25th, 2014
- Automated Web Application Functional Testing - April 1st, 2014
- What Not To Test - April 9th, 2014
- Don’t Comment Out That Test - April 24th, 2014
- The Proper Function of QA - May 1st, 2014
- TDD Saves Time – A Story - May 22nd, 2014
- Running Selenium In Parallel With Any .NET Unit Testing Tool - July 31st, 2014
- It is called "Unit Testing" for a reason - August 28th, 2014
- Is Your Architecture Crippling Your Unit Testing? - September 4th, 2014
- ASP.NET Server Performance Testing - November 6th, 2014
- NUnit & Visual Studio - December 4th, 2014
- NUnit Test Code Structure - February 5th, 2015
- Excuses For Not Testing - February 26th, 2015
- Why Johnny Can't do Test Driven Development - March 5th, 2015
- TDD Gamification - Turning Test Driven Development into a Game - April 23rd, 2015
- SpecFlow Tutorial - June 4th, 2015
- The Fallacy of Motion - July 23rd, 2015
- NUnit 2 vs NUnit 3. What you need to know. - December 3rd, 2015
- 8 Reasons Johnny Does Not Write Bug Free Code - September 20th, 2016
- Property Based Testing Revealed - A Better Way to Test - January 23rd, 2018