我在 NetBeans 中使用 JUnit 运行了一个测试,我得到了这个测试结果:
这是输出消息:
测试运行:0,失败:0,错误:2,经过时间:0,336 秒
------------- 标准输出 --------------- avant tout après tout ------------- --- ------------- ---------------- 测试用例:calculette.calculMethodeTest:在方法 calculette.Calculette.main 中导致错误 Illegal local variable table length 24 ([Ljava/lang/String;)V java.lang.ClassFormatError: Illegal local variable table length 24 in method calculette.Calculette.main([Ljava/lang/String;)V at calculette.calculMethodeTest.setUpClass(calculMethodeTest.java: 24)
测试用例:calculette.calculMethodeTest:在 calculette.calculMethodeTest.tearDownClass(calculMethodeTest.java:30) 处导致 ERROR null java.lang.NullPointerException
测试 calculette.calculMethodeTest FAILED 测试报告:C:\Users\Aimad\Documents\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;
}