Eclipse(Java 测试)- 终止突变体版本

huangapple go评论85阅读模式
英文:

Eclipse(java testing) - terminate mutant version

问题

我是Coursera的“软件测试入门”课程的学习者。我正在提交我的单元测试作业,但Coursera网站上的评分器输出显示如下:

mutant1: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant10: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant15: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant18: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant2: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant21: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant23: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant25: -0.020833333333333332 *** 学习者未正确终止突变版本! ***
mutant3: -0.020833333333333332 *** 学习者未正确终止突变版本! ***

请帮忙!我必须提交作业以获得证书。

// Demo.java

import java.util.Scanner;

public class Demo {

    public static void main(String[] args) {
        // 从System.in读取输入
        Scanner reader = new Scanner(System.in);

        System.out.println("输入边1:");
        // 以整数形式扫描输入的下一个标记。
        int side_1 = reader.nextInt();

        System.out.println("输入边2:");
        // 以整数形式扫描输入的下一个标记。
        int side_2 = reader.nextInt();

        System.out.println("输入边3:");
        // 以整数形式扫描输入的下一个标记。
        int side_3 = reader.nextInt();

        if (isTriangle(side_1, side_2, side_3)) {
            System.out.println("这是一个三角形。");
        } else {
            System.out.println("这不是一个三角形。");
        }

        reader.close();

    }

    public static boolean isTriangle(double a, double b, double c) {
        if ((a + b > c) &&
            (a + c > b) && // 应该是 a + c > b
            (b + c > a)) {
            return true;
        }
        return false;
    }

}

测试代码如下:

import static org.junit.Assert.*;

import org.junit.Test;

public class DemoTest {

    @Test
    public void triangle_test_1() {
        assertTrue(Demo.isTriangle(3, 2, 4));
    }

    @Test
    public void triangle_test_2() {
        assertTrue(Demo.isTriangle(4, 3, 5));
    }

    @Test
    public void triangle_test_3() {
        assertTrue(Demo.isTriangle(5, 3, 5));
    }

    @Test
    public void triangle_test_4() {
        assertTrue(Demo.isTriangle(6, 4, 5));
    }

    @Test
    public void triangle_test_5() {
        assertTrue(Demo.isTriangle(7, 5, 6));
    }

    @Test
    public void triangle_test_6() {
        assertFalse(Demo.isTriangle(13, 2, 4));

    }

    @Test
    public void triangle_test_7() {
        assertFalse(Demo.isTriangle(4, 3, 15));
    }

    @Test
    public void triangle_test_8() {
        assertFalse(Demo.isTriangle(3, 22, 4));
    }

    @Test
    public void triangle_test_9() {
        assertFalse(Demo.isTriangle(24, 2, 5));
    }

    @Test
    public void triangle_test_10() {
        assertFalse(Demo.isTriangle(34, 2, 4));
    }

    @Test
    public void triangle_test_11() {
        assertFalse(Demo.isTriangle(2, 10, 4));

    }

}
英文:

I am a learner on the Coursera "Introduction to Software Testing" course. I am submitting my unit test assignment but the grader output on the Coursera site shows me this:

mutant1: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant10: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant15: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant18: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant2: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant21: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant23: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant25: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***
mutant3: -0.020833333333333332 *** Learner did not properly terminate mutant version! ***

Kindly help! I have to submit the assignment to get a certificate.

// Demo.java
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
// Reading from System.in
Scanner reader = new Scanner(System.in);  
System.out.println("Enter side 1: ");
// Scans the next token of the input as an int.
int side_1 = reader.nextInt();
System.out.println("Enter side 2: ");
// Scans the next token of the input as an int.
int side_2 = reader.nextInt();
System.out.println("Enter side 3: ");
// Scans the next token of the input as an int.
int side_3 = reader.nextInt();
if (isTriangle(side_1, side_2, side_3)) {
System.out.println("This is a triangle.");
}
else {
System.out.println("This is not a triangle.");
}
reader.close();
}
public static boolean isTriangle(double a, double b, double c) {
if ((a + b > c) &&
(a + c > b) && // should be a + c > b
(b + c > a)) {
return true; 
}
return false;
}
}

the testing code is:

import static org.junit.Assert.*;
import org.junit.Test;
public class DemoTest {
@Test
public void triangle_test_1() {
assertTrue(Demo.isTriangle(3,2,4));
}
@Test
public void triangle_test_2() {
assertTrue(Demo.isTriangle(4,3,5));
}
@Test
public void triangle_test_3() {
assertTrue(Demo.isTriangle(5,3,5));
}
@Test
public void triangle_test_4() {
assertTrue(Demo.isTriangle(6,4,5));
}
@Test
public void triangle_test_5() {
assertTrue(Demo.isTriangle(7,5,6));
}
@Test
public void triangle_test_6() {
assertFalse(Demo.isTriangle(13,2,4));
}
@Test
public void triangle_test_7() {
assertFalse(Demo.isTriangle(4,3,15));
}
@Test
public void triangle_test_8() {
assertFalse(Demo.isTriangle(3,22,4));
}
@Test
public void triangle_test_9() {
assertFalse(Demo.isTriangle(24,2,5));
}
@Test
public void triangle_test_10() {
assertFalse(Demo.isTriangle(34,2,4));
}
@Test
public void triangle_test_11() {
assertFalse(Demo.isTriangle(2,10,4));
}
}

答案1

得分: 1

因为他们创建并使用了 Demo.java 的变异版本。变异代码是原始代码的一个版本,只有一个语法上的变化,比如将 '+' 改为 '-',变量 A 改为变量 B,或者 '>' 改为 '>='。

这些变化中的每一个都可能使代码的行为与原始代码不同,您的测试脚本应该能够检测出这些变化。

变异体1:-0.020833333333333332 *** 学习者没有正确终止变异版本! ----- 这意味着您的测试脚本针对变异代码通过了,而实际上不应该通过。这意味着您的测试脚本在代码中可能存在许多可能的错误情况。

尝试:使用 1、2、3 添加输入组合。

英文:

Because they created and used mutant versions of the Demo.java. Mutant code is a version of the original code with single syntactical change, like '+' is changed to '-', variable A to variable B, or '>' changed to '>='.

Each of these changes can make the code behave differently from the original code and your test script should detect these changes.

mutant1: -0.020833333333333332 *** Learner did not properly terminate mutant version! ----- means that your test script passed against a mutant code in which it should not, it means that your test script does not cover much of the possible errors in the code.

Try: add input combinations using 1,2,3

答案2

得分: 0

这个错误只是意味着你没有编写足够的单元测试。 "突变体" 是指被更改的代码,它是无效的,应该导致一些单元测试失败。所以基本上这个错误信息表示测试针对无效更改的代码执行了,并且全部都通过了。因此,你应该添加更多的测试来覆盖所有情况。

英文:

This error just means that you didn't write enough unit tests. "Mutant" is a changed code, which is invalid and which should make some of your unit tests fail. So basically this error message says that tests were executed against invalidly changed code and that all passed. So you should add more test to cover all cases.

huangapple
  • 本文由 发表于 2020年9月30日 18:02:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/64135232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定