我正在使用hamcrest 1.3来测试我的代码.它只是一个骰子.我试图测试它以确保生成的数字小于13.我有一个打印语句打印生成的数字是什么.生成的数量始终小于13,但测试总是失败.有什么我做错了吗?
这是我正在测试的代码.
import java.util.Random;
public class Die {
private int numSides;
Random rand;
public Die(int numSides){
this.numSides = numSides;
rand = new Random(System.currentTimeMillis());
}
public int roll(){
return rand.nextInt(numSides) + 1;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码.
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
public class DieTest {
@Test
public void testRoll() {
Die x = new Die(12);
assertThat(x.roll(), is(lessThan(13)));
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是故障堆栈跟踪.
java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
at …Run Code Online (Sandbox Code Playgroud)