| Version 2 (modified by chenyang, 14 years ago) (diff) |
|---|
单元测试应用示例——测试Service层对象
GameStart是游戏登陆与充值的接口,SxdGameStart实现了GameStart接口,完成了用户登陆神仙道游戏服务器,充值,检验用户是否存在等功能,示例如何测试用户是否存在功能.
prestart(User user,Game game,Server server)方法判断用户在游戏厂商服务器中是否存在,要测试该方法,需要准备user,game,server对象
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class SxdGameStartTest extends AbstractTransactionalJUnit4SpringContextTests{
@Ignore
public void prestart() throws Exception {
GameStart start = (GameStart) applicationContext.getBean("sxdGameStart");
//准备user对象
User user = new User();
user.setUserId(9673315);
user.setName("lifeng");
//准备game
Game game = new Game();
//准备server
Server server = new Server();
server.setStartURL("http://s1.sxd.pcgames.com.cn/login_api.php");
server.setPrestartURL("http://api.sxd.xd.com/api/check_user.php");
server.setLoginkey("{B819BBB7-F049-4D31-ABED-C871DC7628F2}");
server.setPrestartResult("1");
boolean b = start.prestart(user, game, server);
//断言用户存在
Assert.assertTrue(b);
}
...................
}
![(please configure the [header_logo] section in trac.ini)](http://www1.pconline.com.cn/hr/2009/global/images/logo.gif)