Eclipse中运行JUnit5测试抛出java.lang.SecurityException异常:类“org.hamcrest.Matchers”

问题描述 投票:0回答:1

我有一个Maven项目一个简单的JUnit项目。

当我有这个简单的测试:

import java.util.Arrays;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;

import org.junit.jupiter.api.Test;

import lombok.val;

class MyTest {

    @Test
    void test() {
        val list = Arrays.asList(2, 3, 6, 8, 5);
        val expected = Arrays.asList(5, 6);
        assertThat(list, containsInAnyOrder(expected));
    }

}

而我加入了Junit5库的构建路径,我得到这个错误:

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package

我发现,出现这种情况,因为我使用hamcrest-2.1.jar的依赖性和Eclipse使用1.3.0v20180420-1519.jar版本在JUnit5库。

有没有什么办法来解决这个问题,因为我只当我需要使用存在于org.hamcrest.Matchers类的方法有问题。存在于org.hamcrest.CoreMatchers的那些不给任何问题。

我使用的Eclipse版本:2018-12(4.10.0)的Eclipse IDE的企业Java开发。建立ID:20181214-0600

谢谢

eclipse junit5
1个回答
0
投票

由于这个https://code.google.com/archive/p/hamcrest/issues/128有针对此问题的修复程序。仅仅通过行家hamcrest核1.3更换hamcrest罐子的.p2版本。

© www.soinside.com 2019 - 2024. All rights reserved.