我在NetBeans中使用JUnit运行测试,我得到了这个测试结果:
这是输出消息:
测试运行:0,失败:0,错误:2,已过去时间:0,336秒
-------------标准输出--------------- avanttoutaprèstout ------------- ---------------- --------------- Testcase:calculette.calculMethodeTest:导致ERROR非法局部变量 表格长度为24 calculette.Calculette.main([Ljava /郎/字符串;)V java.lang.ClassFormatError:非法局部变量表长度为24英寸 方法calculette.Calculette.main([Ljava / lang / String;)V at calculette.calculMethodeTest.setUpClass(calculMethodeTest.java:24)
Testcase:calculette.calculMethodeTest:导致ERROR为null java.lang.NullPointerException at calculette.calculMethodeTest.tearDownClass(calculMethodeTest.java:30)
测试calculette.calculMethodeTest FAILED测试报告: C:\ Users \用户Aimad \文档\的NetBeansProjects \ Calculette \ nbproject文件\ build-impl.xml中:933: 有些测试失败了;看上面的细节。建筑失败(总时间:12 秒)
这些错误意味着什么?
这是测试方法:
**
* Test of main method, of class Calculette.
*/
@Test
public void testMain() {
System.out.println("main");
String[] args = null;
Calculette.main(args);
}
/**
* Test of multiplication method, of class Calculette.
*/
@Test
public void testMultiplication() {
System.out.println("multiplication");
double a = 2.0;
double b = -5.0;
Calculette instance = new Calculette();
double expResult = -10.0;
double result = instance.multiplication(a, b);
assertEquals(expResult, result, 0.0);
}
/**
* Test of division method, of class Calculette.
*/
@Test (expected = DivisionSurZeroException.class)
public void testDivision() {
System.out.println("division");
double a = 0.0;
double b = 0.0;
Calculette instance = new Calculette();
double expResult = a/b;
double result = instance.division(a, b);
assertEquals(expResult, result, 0.0);
a = 10;
b = 10;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = 10;
b = 0;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = 10;
b = -10;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = 0;
b = 10;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = 0;
b = -10;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = -10;
b = 10;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = -10;
b = 0;
expResult = a/b;
assertEquals(expResult, result, 0.0);
a = -10;
b = -10;
expResult = a/b;
assertEquals(expResult, result, 0.0);
}
/**
* Test of addition method, of class Calculette.
*/
@Test
public void testAddition() {
System.out.println("addition");
double a = -10.1;
double b = -70.0;
Calculette instance = new Calculette();
double expResult = a + b;
double result = instance.addition(a, b);
assertEquals(expResult, result, 0.0);
}
/**
* Test of soustraction method, of class Calculette.
*/
@Test
public void testSoustraction() {
System.out.println("soustraction");
double a = -60.5;
double b = 5.0;
Calculette instance = new Calculette();
double expResult = a - b;
double result = instance.soustraction(a, b);
assertEquals(expResult, result, 0.0);
}
这是原始方法:
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Calculette().setVisible(true);
}
});
}
@Override
public double multiplication(double a, double b) {
return a*b;
}
@Override
public double division(double a, double b) {
if(b == 0) throw new DivisionSurZeroException();
else return a/b;
}
@Override
public double addition(double a, double b) {
return a + b;
}
@Override
public double soustraction(double a, double b) {
return a-b;
}
答案 0 :(得分:0)
尽管0.0
对于测试双数学来说并不是一个非常有意义的增量,但这是一个很好的调用(小,正,非零数字是你通常想要的,请看一下{{3} }),我不相信这是错误的责任。这应该只是导致意外失败的测试。
这个问题似乎在Java 7中出现了对字节码验证器的相关更改。我看来你可以通过传递参数来解决问题
-XX:-UseSplitVerifier
(你可以参考这个discussion about what the delta is如果你需要有关如何设置这些args的帮助)