Junit5 如何消除assertThrows的编译时错误(尽管使用了导入)?(爪哇,日食)

Junit5 如何消除assertThrows的编译时错误(尽管使用了导入)?(爪哇,日食),junit5,eclipse-oxygen,junit-jupiter,Junit5,Eclipse Oxygen,Junit Jupiter,我正在测试我找到的以下代码片段 EclipseOxygen版本:Oxygen.2发行版(4.7.2)-如果有必要的话 import org.junit.jupiter.api.Assertions; .... @Test void exceptionTesting() { Executable closureContainingCodeToTest = () -> {throw new IllegalArgumentException("a message");}; Ass

我正在测试我找到的以下代码片段

EclipseOxygen版本:Oxygen.2发行版(4.7.2)-如果有必要的话

import org.junit.jupiter.api.Assertions;
....
@Test
void exceptionTesting() {
    Executable closureContainingCodeToTest = () -> {throw new IllegalArgumentException("a message");};
    Assertions.assertThrows(IllegalArgumentException.class, closureContainingCodeToTest, "a message");
}
但是,代码不会编译

我得到的错误如下:

类型断言中的方法assertThrows(类、可执行文件、字符串)不适用于参数(类、可执行文件、字符串)DbHandlerTest.java第96行java问题


当然,我的目标不仅仅是测试上面的代码片段,而是为我的代码编写一个测试。请帮忙。

我解决了这个问题。。。 谢谢你提出正确的问题。 接下来的导入是错误的

import org.junit.jupiter.api.Executable;
应该是这样的:

import org.junit.jupiter.api.function.Executable;

能否展开整个导入语句块?该类中还有其他测试需要其他导入。。。导入静态org.junit.jupiter.api.Assertions.assertEquals;导入java.sql.SQLException;导入java.util.Properties;导入org.junit.jupiter.api.Assertions;导入org.junit.jupiter.api.BeforeAll;导入org.junit.jupiter.api.Executable;导入org.junit.jupiter.api.Test;导入org.junit.jupiter.api.TestInstance;导入org.junit.jupiter.api.TestInstance.Lifecycle;不客气。看起来您的类路径中有(或仍然有)多个junit jupiter api版本。