我尝试使用 Pitclipse 进行 Java 突变测试,结果没有显示

发布于 2025-01-20 11:25:51 字数 4405 浏览 2 评论 0原文

我试图在Java中使用Pitclipse对程序进行突变测试,但遇到了一个问题,但我不知道该如何解决。

我正在使用Eclipse IDE和Java SE 1.8。

这是代码:

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

这是使用Junit 4的Junit测试:

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));
    }
}

当我在Junit上运行Pitclilpse时,我会收到以下问题:

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文