0

I tried to do mutation testing on a program using pitclipse in Java but came across an issue and I do not know how to solve it.

I am using the Eclipse IDE and Java SE 1.8.

This is the code:

public class NewTry {
        boolean productIsEven(int a, int b){
            
            int product = 2 %(a * b);
            boolean evenOr = product == 1;
            return evenOr;
        }
    }

and this is the Junit Test using Junit 4:

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

public class NewTryTest {

    NewTry obj;
    @Before
    public void setUp()
    {
        obj=new NewTry();
    }
    
    @Test
    public void testTrue1() {
         
        assertEquals(true, obj.productIsEven(10, 20));
    }
    
    @Test
    public void testTrue2() {
         
        assertEquals(true, obj.productIsEven(2, 17));
    }
    

    @Test
    public void testTrue3() {
         
        assertEquals(true, obj.productIsEven(0, 0));
    }
    
    @Test
    public void testTrue4() {
         
        assertEquals(true, obj.productIsEven(0, 1));
    }
    
    @Test
    public void testTrue5() {
         
        assertEquals(true, obj.productIsEven(2, 15));
    }
    
    @Test
    public void testTrue6() {
         
        assertEquals(true, obj.productIsEven(2, 13));
    }
    
    @Test
    public void testFalse1() {
         
        assertEquals(false, obj.productIsEven(5, 5));
    }
    
    @Test
    public void testFalse2() {
         
        assertEquals(false, obj.productIsEven(1, 13));
    }
    
    @Test
    public void testFalse3() {
         
        assertEquals(false, obj.productIsEven(1, 15));
    }
    
    @Test
    public void testFalse4() {
         
        assertEquals(false, obj.productIsEven(1, 17));
    }
}

I receive the following issue when I run pitclilpse on the junit:

18:26:31 PIT >> SEVERE : Description [testClass=NewTryTest, name=testTrue1(NewTryTest)] did not pass without mutation.
18:26:31 PIT >> SEVERE : Description [testClass=NewTryTest, name=testTrue2(NewTryTest)] did not pass without mutation.
18:26:31 PIT >> SEVERE : Description [testClass=NewTryTest, name=testTrue3(NewTryTest)] did not pass without mutation.
18:26:31 PIT >> SEVERE : Description [testClass=NewTryTest, name=testTrue4(NewTryTest)] did not pass without mutation.
18:26:31 PIT >> SEVERE : Description [testClass=NewTryTest, name=testTrue5(NewTryTest)] did not pass without mutation.
18:26:31 PIT >> SEVERE : Description [testClass=NewTryTest, name=testTrue6(NewTryTest)] did not pass without mutation.
18:26:31 PIT >> FINE : Coverage generator Minion exited ok
18:26:31 PIT >> INFO : Calculated coverage in 5 seconds.
18:26:31 PIT >> SEVERE : Tests failing without mutation: 
Description [testClass=NewTryTest, name=testTrue1(NewTryTest)]
Description [testClass=NewTryTest, name=testTrue2(NewTryTest)]
Description [testClass=NewTryTest, name=testTrue3(NewTryTest)]
Description [testClass=NewTryTest, name=testTrue4(NewTryTest)]
Description [testClass=NewTryTest, name=testTrue5(NewTryTest)]
Description [testClass=NewTryTest, name=testTrue6(NewTryTest)]
Exception in thread "main" org.pitest.help.PitHelpError: 6 tests did not pass without mutation when calculating line coverage. Mutation testing requires a green suite.
See http://pitest.org for more details.
    at org.pitest.coverage.execute.DefaultCoverageGenerator.verifyBuildSuitableForMutationTesting(DefaultCoverageGenerator.java:114)
    at org.pitest.coverage.execute.DefaultCoverageGenerator.calculateCoverage(DefaultCoverageGenerator.java:96)
    at org.pitest.coverage.execute.DefaultCoverageGenerator.calculateCoverage(DefaultCoverageGenerator.java:51)
    at org.pitest.mutationtest.tooling.MutationCoverage.runReport(MutationCoverage.java:115)
    at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:120)
    at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:50)
    at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:87)
    at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:45)
    at org.pitest.pitclipse.runner.PitRunner.lambda$1(PitRunner.java:59)
    at com.google.common.base.Present.transform(Present.java:75)
    at org.pitest.pitclipse.runner.PitRunner.main(PitRunner.java:46)
khelwood
  • 55,782
  • 14
  • 81
  • 108
abc
  • 39
  • 6
  • The product of a and b is even if `(a*b)%2==0`. What you are checking is something else. – khelwood Apr 11 '22 at 15:56
  • @khelwood well yes the program is wrong. Isn't that why mutation testing is done? – abc Apr 11 '22 at 16:01
  • Well the error message says "Mutation testing requires a green suite.", which suggests your tests are supposed to pass, which obviously they do not. – khelwood Apr 11 '22 at 16:16
  • @khelwood What does it mean by green suite? Does that mean I have to remove the failing methods from my Junit test file? – abc Apr 11 '22 at 16:31
  • It means all your tests should pass. – khelwood Apr 11 '22 at 17:39
  • @khelwood oh alright I will modify the junit test file to all passing test cases then, correct? – abc Apr 11 '22 at 17:49

0 Answers0