简体   繁体   中英

SpringJUnit4ClassRunner isn't recognized as a type

My aplication uses Spring 4.3.1 and JUnit 4.12.

I have been trying test my methods with JUnit test cases.

I placed the @RunWith(SpringJUnit4ClassRunner.class) annotation in my test class, but eclipse complains "Class cannot be resolved to a type".

I read that this was enough for Eclipse to recognize SpringJUnit4ClassRunner, but isn't.

Is there Anything else remaining to do?

Try to:

  1. Add spring-starter-test dependency through your configuration file & include relevant import statements in test files.
  2. Delete local dependency repository & force new build to your application.

Adding the dependency spring-test the problem has been solved.

I didn't know there was need for this additional dependence, but someone told me here. Thank you.

I initially said that this measure was not enough because I had written the dependency version name wrongly and Maven was not finding the resource. But now it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM