我正在测试我发现的以下代码片段 here .
Eclipse Oxygen 版本: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");
}
但是,代码无法编译。
我收到以下错误:
The method assertThrows(Class, Executable, String) in the type Assertions is not applicable for the arguments (Class, Executable, String) DbHandlerTest.java line 96 Java Problem
当然,我的目标不仅仅是测试上面的代码片段,而是为我的代码编写一个测试。请帮忙。
最佳答案
我发现问题了... 谢谢somuras对于正确的问题。 以下导入错误
import org.junit.jupiter.api.Executable;
应该是这样的:
import org.junit.jupiter.api.function.Executable;
关于junit5 - 如何消除断言抛出的编译时错误(尽管使用导入)? (Java、Eclipse 氧气),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48517840/