Skip to content

Commit

Permalink
hcoles#510 Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nrainer committed Sep 3, 2018
1 parent 0982044 commit 29d4753
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.coverage.execute.samples.mutationMatrix;

public class SimpleCalculator {

public static int sum(int x, int y) {
return x + y;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.coverage.execute.samples.mutationMatrix;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class TestsForSimpleCalculator {

@Test
public void testSum() {
assertEquals(3, SimpleCalculator.sum(2, 1));
}

@Test
public void testSumWithNegativeNumber() {
assertEquals(1, SimpleCalculator.sum(4, -3));
}

@Test
public void pseudoTestSum() {
SimpleCalculator.sum(2, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ public void runEnd() {
// TODO Auto-generated method stub

}

public List<MutationResult> getData() {
return data;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.example.JUnitThreeSuite;
import com.example.KeepAliveThread;
import com.example.MultipleMutations;
import com.example.coverage.execute.samples.mutationMatrix.TestsForSimpleCalculator;

@Category(SystemTest.class)
public class MutationCoverageReportSystemTest extends ReportTestBase {
Expand Down Expand Up @@ -192,6 +193,26 @@ public void willAllowExcludedClassesToBeReIncludedViaSuite() {
createAndRun();
verifyResults(KILLED);
}

@Test
public void computesFullMutationMatrix() {
this.data
.setTargetTests(predicateFor("com.example.coverage.execute.samples.mutationMatrix.*"));
this.data.setTargetClasses(asList("com.example.coverage.execute.samples.mutationMatrix.*"));
this.data.setExcludedClasses(asGlobs(TestsForSimpleCalculator.class));
this.data.setFullMutationMatrix(true);
this.data.addOutputFormats(Arrays.asList("XML"));
this.data.setMutators(Arrays.asList("MATH"));
createAndRun();
List<MutationResult> resultData = this.metaDataExtractor.getData();
assertEquals(1, resultData.size());

MutationResult mutation = resultData.get(0);
assertEquals(KILLED, mutation.getStatus());
assertEquals(3, mutation.getNumberOfTestsRun());
assertEquals(2, mutation.getKillingTests().size());
assertEquals(1, mutation.getSucceedingTests().size());
}

@Test(expected = PitHelpError.class)
public void shouldExcludeFilteredClasses() {
Expand Down

0 comments on commit 29d4753

Please sign in to comment.