JUnit testing got initializationError with java.lang.Exception: No tests found matching

后端 未结 8 1493
别那么骄傲
别那么骄傲 2021-01-01 18:59

When running JUnit testing , it gave an initializationError: No tests found matching. Like this:

prodapi-main-junit
initializationError(org.junit.runner.man         


        
相关标签:
8条回答
  • 2021-01-01 19:49

    After googled some answers. I found there's an issue talked about this case as below: https://github.com/junit-team/junit4/issues/1277 (FilterRequest may hide the real failure cause(exception) of a test) Here're the steps I tried:
    1. don't select the testing function alone, while select "Run all the tests in the selected project" option on the Test Tab, when select the Junit project name after click on Run->"Run(Debug) Configuration"
    2. You can get the details of the error as follows:

    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)
    

    3.according to the details given by eclipse above, I removed the argument of that function, the initializedError just disappeared.

    So this issue rises due to the new added testing function has unnecessary input argument. The incorrect code :

    @Test
    public void testSetDBConfiguration(String name) throws Exception {
    

    Changed to

    @Test
    public void testSetDBConfiguration() throws Exception {
    
    0 讨论(0)
  • 2021-01-01 19:50

    I have found the below solution which worked for me.

    your Application @SpringBootApplication package name and Test package name should be same .

    see if it helps. Happy coding.

    0 讨论(0)
提交回复
热议问题