码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-15 22:59:59      阅读:182      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!