首页 > 其他 > 详细

junit基础学习之-参数初始化(5)

时间:2015-08-15 22:59:27      阅读:153      评论:0      收藏:0      [点我收藏+]

和之前类似,只有@RunWith和参数那里有变化。

package swust.edu.cn.postdoctors.service.impl;

import java.util.Arrays;
import java.util.Collection;


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.test.context.ContextConfiguration;

import swust.edu.cn.postdoctors.service.UserService;
import junit.framework.TestCase;

@RunWith(Parameterized.class)
@ContextConfiguration(locations={"classpath:spring-mybatis-test.xml"}) // 加载配置 
public class UserServiceTest extends TestCase {


private UserService userService;

public UserService getUserService() {
return userService;
}

public void setUserService(UserService userService) {
this.userService = userService;
}

@Parameters
public static Collection<Object[]> data(){
return Arrays.asList(new Object[][]{{"aa","11"},{"bb","22"},{"cc","33"}});
}
private String inStr;
private String outStr;

public UserServiceTest(String inStr,String outStr){
this.setInStr(inStr);
this.setOutStr(outStr);

}

public String getInStr() {
return inStr;
}

public void setInStr(String inStr) {
this.inStr = inStr;
}

public String getOutStr() {
return outStr;
}

public void setOutStr(String outStr) {
this.outStr = outStr;
}


@Before
public void before() throws Exception {
userService = new UserServiceImpl();
}
@Test
public void testSelectUserByLoginNameAndPswd() throws Exception {
if(userService == null){
System.out.println("========================userService 出错!");
}

swust.edu.cn.postdoctors.model.User resUser = null ;

resUser = userService.findUserByLoginNameAndPswd(this.inStr, this.outStr);

if(resUser == null){    
System.out.println("userService 出错!");
}else{
System.out.println("userService 正确!");
}

}


}

 

junit基础学习之-参数初始化(5)

原文:http://www.cnblogs.com/x739400043/p/4733241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!