I. Join a Dependency package
- Spring Test (e.g. Spring-test-2.5.4.jar)
- JUnit 4
- Spring Other related packages
II. New JUnit Test case
Iii. reading a configuration file
@RunWith (Springjunit4classrunner.class) @ContextConfiguration (locations = {"Classpath:/applicationcontext.xml"})
public class Span style= "color: #000000;" > Goodsservicetest {@Resource private Go Odsservice Goodsserviceimpl; @Test public void Test () { // Load log4j configuration Propertyconfigurator.configure (Test.class.getClassLoader (). GetResource ("log4j.properties" ;
}
}
Note: The Applicationcontext.xml path problem to load: The above code is based on Classpath, Therefore Applicationcontext.xml and log4j.properties must be placed under the Classpath (Details: http://www.cnblogs.com/qiqiweige/p/4916458.html).
III. Running
Right-click Run As-->junit Test
Spring consolidates junit for unit testing