JUnit error java.lang.Exception:No tests found matching
JUnit was recently used in the process of learning spring, but there was a very frustrating error in the middle.
1Java.lang.Exception:No tests found matching [{Exactmatcher:fdisplayname=cdshouldnotbenull], {exactmatcher: Fdisplayname=cdshouldnotbenull (Soundsystem. Cdplayertest)], {Leadingidentifiermatcher:fclassname=soundsystem. Cdplayertest,fleadingidentifier=Cdshouldnotbenull]] From [email protected]2At Org.junit.internal.requests.FilterRequest.getRunner (filterrequest.java:40)3At Org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest (junit4testloader.java:77)4At Org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest (junit4testloader.java:68)5At Org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests (junit4testloader.java:43)6At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:444)7At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:675)8At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382)9At Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:192)
The code is as follows:
1 Import Staticorg.junit.assert.*;2 3 ImportJavax.annotation.Resource;4 5 Importorg.junit.Test;6 ImportOrg.junit.runner.RunWith;7 Importorg.springframework.test.context.ContextConfiguration;8 ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;9 Ten@RunWith (Springjunit4classrunner.class) One@ContextConfiguration (classes = Cdplayerconfig.class) A Public classCdplayertest { - - @Resource the PrivateCompactdisc cd; - - @Test - Public voidCdshouldnotbenull () { + assertnotnull (CD); - } + A}
Carefully check the code should be no problem, the internet looked under, found a lot of friends have also met the problem of the pit dad, finally found the solution is as follows.
Reference Solutions:
In addition to the package that JUnit needs to reference in the code, it involves another jar package if it involves an application context that needs to be created automatically by spring.
Hamcrest-all-1.3.jar
Just introduce this JAR package.
The spring version used by the author is 4.3.5,junit version 4.12.
Reference to the original:
JUnit error java.lang.Exception:No tests found matching
JUnit Error Java.lang.Exception:No tests found matching