maven使用Junit测试

1.maven整个ssh项目使用Junit测试,需要pom.xml中添加Junit依赖和spring-test依赖

2.maven拆分ssh工程时候,如果父工程的pom.xml中没有Junit包和spring-test包,需要在子工程中导入

maven使用Junit测试

3.在单元测试类中通过注解方式或者new 类的方式加载配置文件

maven使用Junit测试

注:@ContextConfiguration("classpath*:spring/applicationContext-*.xml")中的classpath*可以加载jar下同一目录下前缀为applicationContext-的配置文件(由于我拆分工程,dao,service,action拆分开,所以applicationContext-service.xml中配置内容如下)

maven使用Junit测试maven使用Junit测试

4.当run-->test输出控制台出现sql语句,代表测试成功!