Git Product home page Git Product logo

pit-example's Introduction

PIT Example

Example of running PIT mutation testing tool using JUnit

Running

This example uses Maven, a project management tool that neatly takes care of dependencies.

To run the mutation tests, execute the following commands

mvn clean install                              #clean and compile
mvn test                                       #run jUnit
mvn org.pitest:pitest-maven:mutationCoverage   #run PIT mutation tests

If Maven is not available on your system, there is a provided ant script.

ant
ant test
ant pit

If you prefer to run PIT directly via the command line, run the following:

java -cp target/classes:target/test-classes:lib/junit-4.10.jar:lib/pitest-0.25-SNAPSHOT.jar \
    org.pitest.mutationtest.MutationCoverageReport \
    --reportDir target/pit-reports \
    --targetClasses pitexample.* \
    --sourceDirs src/main/java,src/test/java

and see the generated report in target/pit-reports.

Examining the output

The example has the following method

public boolean myMethod(int a, boolean flag) {
    if (a > 0) {
        return true;
    }
    if (flag) {
        return true;
    }
    return false;
}

That is tested with the following:

@Test public void testMe() {
  MyClass sut = new MyClass();
  assertTrue(sut.myMethod(1, true));
  assertTrue(sut.myMethod(2, true));
  assertTrue(sut.myMethod(1, false));
  assertTrue(sut.myMethod(2, false));
  assertFalse(sut.myMethod(0, false));
}

The output from PIT indicates that it created 6 mutations, and only killed 5 of them (83%). Looking at the html output, it becomes clear that there is another assertion missing. Adding the following assertion and rerunning will complete the test.

assertTrue(sut.myMethod(0, true));

Integrating with an existing system

It is imperative that you compile all code with debug information. This means that you must add debug="true" to the javac blocks in your ant file.

pit-example's People

Contributors

klynch avatar lorenzobettini avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.