Getting started

Getting started with NinjaTurtles is simple. To get up and running immediately without writing a single line of code, take a look at the console runner. The rest of this page describes how to add mutation tests to your existing test suite.

Referencing NinjaTurtles

First, your test project needs to reference the NinjaTurtles assembly. The easiest way to do this is to use NuGet – install it as a Visual Studio Extension if you haven’t already. Then you can just use the NuGet package manager to install the NinjaTurtles package into your test project.

Writing your first mutation test

Next, you need to add some mutation tests to your project. There’s a fluent interface for this. Let’s take the simplest case first. I’m going to assume you’re using NUnit as your test framework, and you have a class called ClassUnderTest with a method names MethodUnderTest that you want to test. First, you need a MutationTestBuilder for this class:

MutationTestBuilder<ClassUnderTest>

Then you need to tell it your mutation tests are for MethodUnderTest:

MutationTestBuilder<ClassUnderTest>
    .For("MethodUnderTest")

And finally, you need to run the tests:

MutationTestBuilder<ClassUnderTest>
    .For("MethodUnderTest")
    .Run();

Do this within another NUnit test, to which you also add the MutationTestAttribute:

[Test, MutationTest]
public void MethodUnderTest_Mutation_Tests()
{
    MutationTestBuilder<ClassUnderTest>
        .For("MethodUnderTest")
        .Run();
}

That’s it. If you run this test, it will identify from your unit tests in the same assembly which tests exercise this method, and then for each possible mutant that it finds, it will run that test suite. If at least one of those tests fail, then the mutant is killed, which is good. If the mutant survives, then you’ll be given the line of code at the point where the mutant failed, and you will be able to examine the mutated DLL in a temporary folder if you need to help diagnose the problem.

In the next section, we’ll look at private classes and overloaded methods.