Spring project with JUnit appears Org.junit.runners.BlockJUnit4ClassRunner cannot be resolved

Source: Internet
Author: User

When the Spring Framework project is tested with JUnit, the program automatically compiles with the following issues:

The problem with the program is that there are no Org.junit.runners.BlockJUnit4ClassRunner found in the project, there are two possibilities, one is that the jar is not imported into JUnit, and the other is that there is no such class in the version of the imported JUnit jar.

1, first confirm whether to import the jar package



2, since the jar has been imported, then on the JUnit website to see the version of JUnit now



Summarize:

1, fully can certainly be the version issue, JUnit for a higher version, problem solving.

2, after investigation to understand that Spring3 provides Springjunit4classrunner base class so that we can easily access JUNIT4, and Org.springframework.test.context.junit4.SpringJUnit4ClassRunner Inherit the Org.junit.runners.BlockJUnit4ClassRunner, where the Blockjunit4classrunner class is included in the version above junit4.5.


3, when using junit4.11 version, the official website is required junit-4.11.jar + Hamcrest-core-1.3.jar, if not added hamcrest-core-1.3.jar java.lang.noclassdeffounderror:org/hamcrest/ Selfdescribing error. If the 4.11 version requires two jars Plus, or a lower version, &NBSP is provided in the shared file below, and the junit4.7 version.  





Warm tips: The junit-4.11 jar package is shared, and the shared file includes JUnit's jar package, source code, documentation.

Baidu Network disk: Link: http://pan.baidu.com/s/1mgvFIje Password: 8SSF

2017-12-27 Update
Oneself also encountered this problem, according to the above solution not, their own MAVEN import is junit4.12 later himself after debugging found, is the version problem, changed to 4.11 No problem, the code is as follows

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration"classpath:spring/spring-dao.xml""classpath:spring/spring-service.xml" })publicclass BaseTest {}

Spring project with JUnit appears Org.junit.runners.BlockJUnit4ClassRunner cannot be resolved (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.