简体   繁体   English

在 Junit 测试中使用 assertEquals。 我该如何纠正?

[英]Using assertEquals in Junit test. How can I correct it?

public class MyTestCase {
    private MaxHeap testHeap;
    MaxHeap Student = new MaxHeap();

       @Before
       public void setUp() throws Exception
       {
           testHeap = new MaxHeap(10);
           testHeap.insert(new Student("Susan", 60, 3.5));
           testHeap.insert(new Student("Ben", 70, 3.4));
           testHeap.insert(new Student("Reed", 120, 4.0));
           testHeap.insert(new Student("Troy", 90, 1.1));
           testHeap.insert(new Student("Johnny", 50, 2.3));

       }
       @Test

       public void testInsert() {
           Student.name("Ciroc");
           Student.setGPA(3.3);
           Student.setUnits(75);

           double testCase = MaxHeap.insert(students);
           assertEquals(3.3, testHeap.extractMax().gpa(), 0.0);
       }
}

I like to use JUnit test, to test the insert method in the heap, if the student with higher GPA will replace the student with the lower GPA.我喜欢用JUnit测试,测试堆中的insert方法,如果GPA高的学生会替换GPA低的学生。 This is the first time I use JUnit.这是我第一次使用 JUnit。 I'm not sure if it's right, please correct me.不知道对不对,请指正。 Thank you.谢谢你。

Here is the link for MaxHeap and Student class Click Here这是 MaxHeap 和 Student 类的链接单击此处

Yes.是的。 It's correct.这是正确的。

@param expected - expected value
@param actual - the value to check against <code>expected</code>
@param delta - the maximum delta between <code>expected</code> and  

static public void assertEquals(double expected, double actual, double delta) {...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用assertEquals编写Junit测试,以查看将使用多少硬币退还给我? - How can I write a Junit test using assertEquals to see how many of each coins will be returned to me using? 使用assertEquals时,JUnit测试发生意外故障 - Unexpected failure on JUnit test when using assertEquals 我有两种方法需要使用JUnit测试进行测试。 这是代码 - I have two methods that need to be tested using the JUnit test. Here are the codes 如何使用assertEquals测试Java中的集合元素? - How to test using assertEquals an element of a Set in Java? 如果测试不在测试目录中但在主目录中并且类名没有。* Test。*之类的关键字,如何在Maven中运行JUnit Test - How to run JUnit Test in maven if the test are not in test dir but in main dir and the classname are not having keywords like .*Test.* JUnit =红色条,即使我的assertEquals是正确的 - JUnit = red bar, even if my assertEquals is correct assertEquals()和Assert.assertEquals()之间的JUnit测试差异 - JUnit test difference between assertEquals() and Assert.assertEquals() 如何在Junit中使用assertEquals解决此问题? - How to fix this problem with assertEquals in Junit? 如何使用Epsilon的assertEquals在JUnit中断言两个双精度? - How to Assert Two doubles in JUnit Using assertEquals with Epsilon? JUnit测试后清理数据库。 - Clean up database after JUnit test.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM