Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 对于预期值,正确的断言是什么?_Java_Junit - Fatal编程技术网

Java 对于预期值,正确的断言是什么?

Java 对于预期值,正确的断言是什么?,java,junit,Java,Junit,我正在学习使用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 int

我正在学习使用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)
assertTrue(a.getValue(5)<5);
我不能查找确切的语法,但你应该查看hamcest匹配器。
assertThat(a.getValue(5),matchers.lessThan(5))
。如果它掉了,你会得到assertTrue会给出的更好的错误消息。
public static void assertTrue(boolean condition)