I used MyEclipse 10, and I've been trying to use JUnit to test class methods that contain spring annotations or dynamic injections, but because of the relevant jar files found on the web for testing, always reported such errors, today inadvertently found that MyEclipse has brought Spring is based on JUnit's test framework and is very useful.
1. Needless to say, first add the test framework's Class Library: Project-->buildpath-->addlibraries-->myelipse libraries-->spring 2.5 Testing Support libraries (I use 2.5, the specific version is selected by the spring version of your own project)-->finish. At this point, all the relevant jar packages of the test framework are added to the project.
There are two more class libraries in this project
2. Start writing our test cases. On the code:
Package Com.m6699.cyt.dao.jdbc.oracle;import static Org.junit.assert.*;import Org.junit.test;import Org.junit.runner.runwith;import Org.springframework.test.context.contextconfiguration;import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner, @RunWith (Value=springjunit4classrunner.class) @ Contextconfiguration (locations={"Classpath*:/spring.xml", "Classpath*:/spring-security.xml", "classpath*:/ Spring-quartz.xml "}) public class Jdbcoracleorderdaotest { @Testpublic void Testchangestate () {System.out.println ("Quasi-United States, can finally junit test");//fail ("not yet implemented");}}
Note: @RunWith
@ContextConfiguration
The equivalent of a spring-loaded configuration file, and a test class.
These two annotations are added with detailed usage, the articles related to the Web are written a lot, no longer to be described.
3. Then we run our test cases and show the Green Pass, and the junit that supports spring injection runs successfully. (You may encounter problems, such as the @postconstruct class found at load time, unable to load the injection, then comment out this is good)
The use of @postconstrutct is quite large, see in detail: http://blog.csdn.net/yaerfeng/article/details/8447530
Original: Spring integrates the JUnit test framework (easy tutorial based on MyEclipse, no hassle in guide package)