Ron*_*Ron 6 junit spring unit-testing
When running JUnit testing , it gave an initializationError: No tests found matching. Like this:
prodapi-main-junit
initializationError(org.junit.runner.manipulation.Filter)
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testCreateSite], {ExactMatcher:fDisplayName=testCreateSite(com.company.product.api.web.rest.HostControllerTest)], {LeadingIdentifierMatcher:fClassName=com.company.product.api.web.rest.HostControllerTest,fLeadingIdentifier=testCreateSite]] from org.junit.internal.requests.ClassRequest@3c0f93f1
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Run Code Online (Sandbox Code Playgroud)
While the testing code is as below:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ProductApplication.class)
@WebAppConfiguration
public class HostControllerTest{
@Test
public void testCreateSite() throws Exception {
......
}
}
Run Code Online (Sandbox Code Playgroud)
It should be fine to load the class, running well. There're other modules similar with this one, they're fine to run.
I have checked the possible causes:
I don't know whether there're any other possible things can get Junit testing error like this. Maybe I should check the class loader?
谷歌搜索后的一些答案。我发现有一个关于这种情况的问题,如下所示:https :
//github.com/junit-team/junit4/issues/1277(FilterRequest可能会隐藏测试的真正失败原因(异常))这是我的步骤尝试过:
1.不要单独选择测试功能,而是在“测试”选项卡上选择“运行所选项目中的所有测试”选项,然后单击“运行”->“运行(调试)配置”后选择Junit项目名称。
2.您可以按以下方式获取错误的详细信息:
initializationError(com.company.product.api.web.rest.HostControllerTest)
java.lang.Exception: Method testSetDBConfiguration should have no parameters
at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:76)
at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:155)
Run Code Online (Sandbox Code Playgroud)
3.根据上面的eclipse给出的细节,我删除了该函数的参数,initializedError消失了。
因此,由于新添加的测试功能具有不必要的输入参数,因此出现了此问题。错误的代码:
@Test
public void testSetDBConfiguration(String name) throws Exception {
Run Code Online (Sandbox Code Playgroud)
变成
@Test
public void testSetDBConfiguration() throws Exception {
Run Code Online (Sandbox Code Playgroud)
PowerMock 有同样的问题,@RunWith(PowerMockRunner.class)然后发现我@Test的实现是错误的。正在使用
import org.junit.jupiter.api.Test;
我切换到import org.junit.Test;并解决了我的问题。
| 归档时间: |
|
| 查看次数: |
17468 次 |
| 最近记录: |