Define, Combine, Visualize and Replay hundreds of test cases with a few lines of code! Website and source code: http://github.com/jeromerg/NCase NCase is a mix between a Mocking Framework like Moq and a parametrized test framework, having advanced combinatorial capabilities. NCase is not released yet! The API is now quite stable, but further commits may introduce breaking changes. Please give as much feedback as possible, positive, negative, critics!


Keywords
arrange, test-case, xunit, dsl, act, nunit, pairwise, moq, combinatorial, testing, combinatorics, assert, test
License
Apache-2.0
Install
Install-Package NCase -Version 0.2.0.276

Documentation

See the slides on slides.com or download the PDF

loading slides

Status:

Build status NuGet

(Related projects: NVisitor, NDocUtil, NUtil, NGitVersion)

NCase

Define, Combine, Visualize and Replay hundreds of test cases with a few lines of code.

NCase is a mix between a Mocking Framework like Moq and a parametrized test framework, having advanced combinatorial capabilities.

It can also be used alone to generate a set of data based on combinatorial rules.

Installation

The easiest way is to install NCase with Nuget.

In combination with NUnit:

Install-Package NCase, NCase.NunitAdapter

In combination with XUnit:

Install-Package NCase, NCase.XunitAdapter

First Steps

Create a new console application containing the following lines:

public interface IVar
{
    int X { get; set; }
    int Y { get; set; }
}

public static void Main()
{
    var builder = NCase.NewBuilder();
    var v = builder.NewContributor<IVar>("v");
    var mySet = builder.NewCombinationSet("c");

    using (mySet.Define())
    {
        v.X = 0;
        v.X = 1;

        v.Y = 0;
        v.Y = 1;
    }

    string table = mySet.PrintCasesAsTable();

    Console.WriteLine(table);
}

Ensure that the configuration is set to DEBUG. Execute the program. The result in the console should look like:

 # | v.X | v.Y
 - | --- | ---
 1 |   0 |   0
 2 |   0 |   1
 3 |   1 |   0
 4 |   1 |   1

TOTAL: 4 TEST CASES

Bingo! You generated your first set of test cases.

Now, add the following lines to use each combination:

foreach (Case c in mySet.Cases().Replay())
    Console.WriteLine("{0} ^ {1} = {2}", v.X, v.Y, v.X ^ v.Y);
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0

It generates and replays all test cases one by one!

Discovering NCase

See the long introduction

Next Steps

First, have fun with NCase!

Then, please provide feedbacks, critiques, and suggestions!