ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java – JUnit说我的测试方法“无法解析为一个独特的方法”

2019-07-24 16:00:14  阅读:498  来源: 互联网

标签:java intellij-idea junit5


尝试使用IntelliJ IDEA学习JUnit 5.创建了一个测试类并尝试测试一个方法.这是消息(见第三行):

INFO: Discovered TestEngines with IDs: [junit-jupiter]
Internal Error occurred.
org.junit.platform.commons.util.PreconditionViolationException:'DirectoryTest#directory2bytes' could not be resolved to a unique method
at org.junit.platform.engine.discovery.DiscoverySelectors.lambda$selectMethod$1(DiscoverySelectors.java:131)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(DiscoverySelectors.java:130)
at com.intellij.junit5.JUnit5TestRunnerUtil.createSelector(JUnit5TestRunnerUtil.java:111)
at com.intellij.junit5.JUnit5TestRunnerUtil.buildRequest(JUnit5TestRunnerUtil.java:86)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:46)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 254
Empty test suite.

我无法理解为什么这个方法无法解决:它编译并且肯定存在:

@Test
void directory2bytes( ) {
    testBytes = testDir.directory2bytes();
    for( int i = 0; i <= 10; i++) {
        System.out.print( testBytes[i] + " ")
    }
    System.out.println( );
}

我已经定义了这个:

@BeforeEach
void setUp( ) {
    testDir = new Directory( )
    testBytes = new byte[1000];
}

更新:退出并重新启动IntelliJ IDEA,我现在收到无法解析导入符号“junit”的消息,以及各种注释“@beforeEach”,“afterEach”和“Test”.

更新2:找到并修复了测试类中缺少的分号,但没有更改.注意:我正在测试的某些类中存在编译错误,但我将测试运行配置设置为“构建,无错误检查”.这是正确的吗?我也尝试使用JUnit 4创建相同的测试(使用不同的类名),但这也不起作用.

以下是几行错误消息:

Dec 07, 2016 9:51:41 AM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFO: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage]
Internal Error occurred.
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: DirectoryTest
at org.junit.platform.engine.discovery.MethodSelector.lambda$lazyLoadJavaClass$0(MethodSelector.java:154)

解决方法:

由于bug,M2不支持选择带参数的方法.这在M3中得到修复.但是,要在IntelliJ IDEA中使用M3开箱即用,您需要2016.3.1,它将在下周发布.有一个workaround使用M3与当前版本的IntelliJ IDEA.

标签:java,intellij-idea,junit5
来源: https://codeday.me/bug/20190724/1523965.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有