我正在尝试在 Junit5 中运行测试,它应该从方法中捕获异常。它捕获 NoSuchMethodError 而不是异常异常。
方法:
public void thisMethodShouldThrowException() throws IllegalArgumentException {
throw new IllegalArgumentException();
}
测试方法:
@Test
void thisMethodShouldThrowException() throws IllegalArgumentException {
DBProperties dbProperties = DBProperties.getInstance();
Assertions.assertThrows(IllegalArgumentException.class,
()->dbProperties.thisMethodShouldThrowException());
}
构建.gradle:
dependencies {
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.0-alpha4'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0'
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.0.0'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.0'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.0.0'
testCompile("org.junit.vintage:junit-vintage-engine:4.12.0")
}
堆栈跟踪:
org.opentest4j.AssertionFailedError: Unexpected exception type thrown ==>
Expected :<java.lang.IllegalArgumentException>
Actual :<java.lang.NoSuchMethodError>
<Click to see difference>
Intellij Idea 版本是 2018.2 我也尝试了最新版本的 Junit5。我不知道我做错了什么。你能帮助我吗?
慕姐8265434
哆啦的时光机
相关分类