首页 > 解决方案 > Eclipse:Junit 我在下面的 junit 选项卡中看到了这个错误

问题描述

下面是我的简单代码

package M06;

    public class ExerciseE03 {

        public double calcTotal (double total, boolean existingMember, boolean validDiscount, boolean validCoupon) {

            double discount=0.0;

            if (existingMember && validDiscount || validCoupon) {
                if (total > 1_000.0)
                    discount = 0.15;
                else
                    if (total >= 750)
                        discount = 0.1;
                    else
                        if (total > 500)
                            discount = 0.05;
                        else
                            discount = 0.025;
            }
            return (total * (1-discount) * 1.0825);
        }
    }

这是第 j 个单元文件

package M06;

import static org.junit.Assert.*;
import static junitparams.JUnitParamsRunner.$;
import org.junit.Before;
import org.junit.Test;

import junitparams.FileParameters;

public class ExerciseE03Test {
    private ExerciseE03 object;

    @Before
    public void setUp() throws Exception {
        object = new ExerciseE03();
    }

    @Test
    @FileParameters("src/M06/E03TestCaseTable.csv")
    public void test(int testcaseNumber, boolean member, boolean disc, boolean coupon, double total, double discount, double output) {
        //ExerciseE03 object = new ExerciseE03();
        //assertEquals(1380.1875, object.calcTotal(1500, true, true, true),0.001);
        object.calcTotal( total, member, disc, coupon);
        assertEquals(output,object.calcTotal(total, member, disc, coupon),0.01);
    }

}

我还在下面提供了我的 junit 屏幕截图。由于我是 juint 新手,我不知道针对此类错误应采取哪些步骤

在此处输入图像描述

以上是我可以在下面的 junit 选项卡中看到的错误。

标签: javaeclipsetestingjunitinitialization

解决方案


使用测试类ExerciseE03Test 顶部的@RunWith(JUnitParamsRunner.class) 注释。

@RunWith(JUnitParamsRunner.class)
public class ExerciseE03Test {

查看这篇文章以了解更多信息。


推荐阅读