我正在学习使用 Junit。我编写了一个方法,它生成一个严格小于 xX 的数字。
我想使用 Junit 来测试它。不确定要使用哪个断言是基于 xX 的预期,而且我没有看到任何比较断言。
// within the Junit test class
ClassA a = new ClassA();
@Test
void randomTest(){
assertEquals( ? ,a.getValue(5));
}
public int getValue(int xX){
// returns an integer less than xX
return (int) (Math.random() * xX);
}
最佳答案
使用assertTrue
喜欢 assertTrue(a.getValue(5)<5);
public static void assertTrue(boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionError without a message.
关于java - 对于预期值使用的正确断言是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55840691/