junitjava.lang.Exception: No tests found matching

Open source software supply chain lighting plan, waiting for you>>>

JUnit error java.lang.exception: no tests found matching

Recently, I used JUnit in the process of learning spring, but I encountered a crazy error

1 java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=cdShouldNotBeNull], {ExactMatcher:fDisplayName=cdShouldNotBeNull(soundsystem.CDPlayerTest)], {LeadingIdentifierMatcher:fClassName=soundsystem.CDPlayerTest,fLeadingIdentifier=cdShouldNotBeNull]] from org.junit.internal.requests.ClassRequest@3deff3
2     at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
3     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
4     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
5     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
6     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
7     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
8     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
9     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

The code is as follows:

 1 import static org.junit.Assert.*;
 2 
 3 import javax.annotation.Resource;
 4 
 5 import org.junit.Test;
 6 import org.junit.runner.RunWith;
 7 import org.springframework.test.context.ContextConfiguration;
 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 9 
10 @RunWith(SpringJUnit4ClassRunner.class)
11 @ContextConfiguration(classes = CDPlayerConfig.class)
12 public class CDPlayerTest {
13 
14     @Resource
15     private CompactDisc cd;
16 
17     @Test
18     public void cdShouldNotBeNull(){
19     assertNotNull(cd);
20     }
21 
22 }

After carefully checking the code, there should be no problem. After checking on the Internet, I found that many friends have also encountered this problem. Finally, I found the solution as follows

Reference solution:

It turns out that apart from the packages that JUnit needs to refer to in the code, if the application context that spring needs to create automatically is involved, another jar package is also involved
hamcrest-all-1.3. Jar
just import this jar package

Original reference:
JUnit error java.lang.exception: no tests found matching

Similar Posts: