Like before, only the @runwith and parameters change there.
PackageSwust.edu.cn.postdoctors.service.impl;Importjava.util.Arrays;Importjava.util.Collection;ImportOrg.junit.Before;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.junit.runners.Parameterized;Importorg.junit.runners.Parameterized.Parameters;Importorg.springframework.test.context.ContextConfiguration;ImportSwust.edu.cn.postdoctors.service.UserService;Importjunit.framework.TestCase; the @RunWith (parameterized.class) @ContextConfiguration (Locations={"Classpath:spring-mybatis-test.xml"})//Load Configuration Public classUserservicetestextendsTestCase {PrivateUserService UserService; PublicUserService Getuserservice () {returnUserService;} Public voidSetuserservice (UserService userservice) { This. UserService =UserService;} @Parameters Public StaticCollection<object[]>data () {returnArrays.aslist (Newobject[][]{{"AA", "one"},{"BB", "},{", "CC", "33"}});}PrivateString inStr;PrivateString outstr; Publicuserservicetest (String instr,string outstr) { This. SETINSTR (INSTR); This. SETOUTSTR (OUTSTR);} PublicString getinstr () {returninStr;} Public voidsetinstr (String inStr) { This. inStr =inStr;} PublicString getoutstr () {returnoutstr;} Public voidsetoutstr (String outstr) { This. outstr =outstr;} @Before Public voidBefore ()throwsException {userservice=NewUserserviceimpl ();} @Test Public voidTESTSELECTUSERBYLOGINNAMEANDPSWD ()throwsException {if(UserService = =NULL) {System.out.println ("========================userservice Error!" ");} Swust.edu.cn.postdoctors.model.User Resuser=NULL; Resuser= USERSERVICE.FINDUSERBYLOGINNAMEANDPSWD ( This. INSTR, This. outstr);if(Resuser = =NULL) {System.out.println ("UserService Error!" ");}Else{System.out.println ("UserService Right!" ");}}}
JUnit Basic Learning-parameter initialization (5)