A small adapter between NSpec and NUnit - allows you to run NSpec examples using an NUnit runner. This is useful if your test infrastructure is based on NUnit but you want to migrate to NSpec, or if you find that good tooling doesn't have NSpec support.
Install using Package Manager Console in Visual Studio:
Install-Package NSpecInNUnit
Or if you prefer a UI, find it via the Manage NuGet Packages for Solution menu.
Once installed, it's a matter of using the base class:
using NSpec;
using NSpecInNUnit;
public class my_examples : nspec_as_nunit<my_examples> {
public void describe_the_examples() {
it["should work"] = () => Assert.That(1, Is.EqualTo(2));
}
}
Note that the base class is a generic class that has to be parameterized with the examples
class (here my_examples
). This is required because of how NUnit 3 test data sources works.
For more information about NSpec, please visit http://nspec.org/.
NSpec no longer ships with its own assertions (other than a few limited). You can use NUnit assertions like in the example above or install another assertion library.
⚠ If you use a non-NUnit assertion library like FluentAssertions and have no NUnit Assert statements
at all, NUnit may not detect any tests in the assembly. To fix this, add the [TestFixture]
attribute
to at least one of your example classes.
- Only works with NUnit 3.7 and later (due to this bug).
- Only works with NSpec 3.0.3 and later (due to .NET Core support)
- For NUnit 2 support, please use NSpecInNUnit 2.0.1.
- For NSpec 1 support, please use NSpecInNUnit 1.0.1.
- All examples are run together. Running a single test (e.g. via ReSharper) only affects the test reporting.
NSpecInNUnit targets .NET Framework 4.5.2 as well as .NET Standard 1.6. Thanks to David Vedvick for making the required changes!
- Capture console output (issue #10).
- Now depends on NUnit 3.9.0.
- Now depends on NSpec 3.1.0 (required since 3.1.0 is not binary compatible with 3.0.7).
- Targets both .NET Framework 4.5.2 and .NET Standard 1.6.
- Now depends on NUnit 3.7.0.
- Now depends on NSpec 3.0.3.
- Now depends on NUnit 3.6.0.
- Remove unnecessary NUnit references.
- Target .NET 4.5.2.
- Use NSpec 2.1.0.
- Target .NET 4.5, because one reason to stick to NSpec 1 is because you need to use .NET 4.5 or 4.5.1, so it makes sense that NSpecInNUnit doesn't have a requirement on a newer version.
- First version, works with NSpec 1 and NUnit 2.
The code is licensed under the MIT license. See https://per.mit-license.org/2016