0

我在 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;
    }
4

1 回答 1

0

虽然这是一个很好的调用,0.0但对于测试双重数学并不是一个非常有意义的增量(小、正、非零数是您通常想要的,请查看此处以了解有关增量是什么的一些讨论),但我不相信这是错误的罪魁祸首。这只会导致测试意外失败。

此问题似乎与 Java 7 中字节码验证器的相关更改有关。我似乎可以通过传递参数来解决此问题

-XX:-UseSplitVerifier

(如果您需要有关如何设置这些参数的帮助,可以参考此NetBeans 资源)

于 2013-04-19T22:20:23.990 回答