如何为方法编写Junit测试用例

时间:2019-07-18 06:52:32

标签: junit4

我对Junit测试非常陌生,请让我知道如何模拟此方法并在JUNIT中进行测试:

enter image description here

1 个答案:

答案 0 :(得分:0)

嗨,您可以编写这样的测试类

public class MyTests {    
  @Test
  public void multiplicationOfZeroIntegersShouldReturnZero() {
       MyClass tester = new MyClass(); // MyClass is tested

       // assert statements
       assertEquals(0, tester.multiply(10, 0), "10 x 0 must be 0");
       assertEquals(0, tester.multiply(0, 10), "0 x 10 must be 0");
       assertEquals(0, tester.multiply(0, 0), "0 x 0 must be 0");
  }
}

有关更多信息,请检查此链接 https://www.vogella.com/tutorials/JUnit/article.html