标签:
和之前类似,只有@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 正确!"); } } }
标签:
原文地址:http://www.cnblogs.com/x739400043/p/4733241.html