小编bea*_*w08的帖子

hamcrest测试总是失败

我正在使用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)

java junit hamcrest

43
推荐指数
6
解决办法
3万
查看次数

标签 统计

hamcrest ×1

java ×1

junit ×1