TestNG 集成Spring-test
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TestNG 集成Spring-test相关的知识,希望对你有一定的参考价值。
需要集成上一篇博客 《TestNG单元测试》
导包
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.1.9.RELEASE</version> </dependency>
1 Simple test
package com.zzwx.test.springtestngdbunit; import java.util.List; importorg.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; importorg.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.zzwx.dao.entity.sys.Menu; import com.zzwx.service.UserService; import com.zzwx.test.dbunit.DBUnitEachAll; /** * @author Roger * @desc testng集成Spring */ @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) publicclass TestSimple extends AbstractTestNGSpringContextTests{ @Autowired private UserService userService; private DBUnitEachAll dbunit; @BeforeTest publicvoid beforeTest(){ dbunit = new DBUnitEachAll(); dbunit.setUpBackupEachAll("testSimple.xml", "sys_menu"); } @Test publicvoid testSimple(){ List<Menu> menus = userService.findMenus(); System.out.println("菜单列表:"+menus); } @AfterTest publicvoid afterTest(){ dbunit.recoverBackupEachAll(); } }
2 result
. . . . . 菜单列表:[Menu [id=1, menuName=权限管理1, menuUrl=null], Menu [id=2, menuName=系统管理1, menuUrl=null], Menu [id=3, menuName=日志管理1, menuUrl=null], Menu [id=4, menuName=用户管理1, menuUrl=null], Menu [id=7, menuName=会员列表1, menuUrl=null]] PASSED: testSimple =============================================== Default test Tests run: 1, Failures: 0, Skips: 0 =============================================== =============================================== Default suite Total tests run:1, Failures: 0, Skips: 0 . . . . .
本文出自 “10950988” 博客,请务必保留此出处http://10960988.blog.51cto.com/10950988/1791042
以上是关于TestNG 集成Spring-test的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins如何集成运行testng.xml文件的解决方案