需要集成上一篇博客 《TestNG单元测试》
导包
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.1.9.RELEASE</version> </dependency>
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(); } }
. . . . . 菜单列表:[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
原文地址:http://10960988.blog.51cto.com/10950988/1791042