NSpectator is ready-to-use solution for development using .NET with Context/Specification flavor. It can be used in different approaches where Specification-By-Example is applicable, including TDD, ATDD, BDD or another agile technics. Toolset is intended to be used to drive development through specifying behavior and interaction at the unit level. NSpectator has only one dependency on popular flexible FluentAssertions library. It`s important not to depend on specific unit test framework.
Development was started by Jonny Novikov inspired by RSpec and based upon hereditary framework NSpec written by Matt Florence and Amir Rajan. We shaped and benefited by hard work from our contributors
We recommended installing the NuGet package. Install on the command line from your solution directory or use the Package Manager console in Visual Studio:
PM> Install-Package NSpectator
Please have a look at this wiki page for an overview on which test hooks are executed when: execution order in xSpec family frameworks can get tricky when dealing with more complicated test configurations, like inherithing from an abstract test class or mixing before_each
with before_all
at different context levels.
Test frameworks of the xUnit family have dedicated attributes in order to support data-driven test cases (so-called theories). NSpectator, as a member of the xSpec family, does not make use of attributes and instead obtains the same result with a set of expectations automatically created through code. In detail, to set up a data-driven test case with NSpectator you just:
- build a set of data points;
- name and assign an expectation for each data point by looping though the whole set.
Any NSpectator runner will be able to detect all the (aptly) named expectations and run them. Here you can see a sample test case, where we took advantage of NSpectator.Each<>
class and NSpectator.Do()
extension to work more easily with data point enumeration, and NSpectator.With()
extension to have an easier time composing text:
class Describe_prime_factors : Spec
{
void Given_first_ten_integer_numbers()
{
new Each<int, int[]>
{
{ 0, new int[] { } },
{ 1, new int[] { } },
{ 2, new[] { 2 } },
{ 3, new[] { 3 } },
{ 4, new[] { 2, 2 } },
{ 5, new[] { 5 } },
{ 6, new[] { 2, 3 } },
{ 7, new[] { 7 } },
{ 8, new[] { 2, 2, 2 } },
{ 9, new[] { 3, 3 } },
}.Do((given, expected) =>
it[$"{given} should be {expected}"] = () => given.Primes().Should().Be(expected)
);
}
}
Take a look at separate Katas repository
Check out this wiki page for complete guide.
Feature requests, bugs & issues are handled on NSpectator Youtrack InCloud
Use github authorization (gray bottom button) for signup or login.
MIT © NSpectator Development Team
Jetbrains Community Support for providing great tools for NSpectator Development Team
NDepend for providing our team ultimate tool for deep code analysis