java - 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 选项卡中看到的错误。
解决方案
使用测试类ExerciseE03Test 顶部的@RunWith(JUnitParamsRunner.class) 注释。
@RunWith(JUnitParamsRunner.class)
public class ExerciseE03Test {
查看这篇文章以了解更多信息。
推荐阅读
- php - 翻译日期(输出 ACF,wordpress)
- pandas - 如何创建 .py 到 .exe 的熊猫代码?
- python - 为什么 NetworkX 会为无向图生成不对称的邻接矩阵
- django - Django在主/详细信息中保存聚合(多对一关系)?
- vue.js - VueJs:包装 el-select:在 DOM 刷新期间添加了 3 次列表元素
- javascript - javascript 事件的设备方向未在 chrome android 中触发
- c# - 调试时在 mvc razor 视图中忽略所有命名空间
- transformation - 以下关于 Mapplet 的陈述在 Informatica 中正确且正确的是?
- reactjs - 从 React JS 中的子组件更新道具
- jupyter-notebook - 从 colab 磁盘打开 ipynb 文件