1、在父工程的pom文件中加入spring-test.jar包和Junit-test.jar
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency>
2、重新install 一下父工程,否则在执行run方法时会报错
3、创建test类,在类的头部添加注解即可
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:spring/applicationContext-*.xml") public class UserTest { @Autowired private UserService userService; @Test public void test() { TUser user = new TUser(); user.setAge(0); int addUser = userService.addUser(user); System.out.println(addUser); } }