????????????????????
???????????? ???????[ 2014/10/16 11:40:31 ] ??????????????? ???????
??????????????д???в???????飬???·???????о??????????????????????????????????????????????????????????ν??????????????ν????2??????feed4junit??????·??????junit 4??feed4junit???????????????Щ?????????
???????????????????????????????????????????????????????????????????????????????????в????????????????????Щ?·??????????????????????д???case?????????????????
??????????????????junit 4????????????????????????????????????????????
??????????????
publicclassUserAccess {
// simple validation for user name and password
publicstaticboolean accessCheck(String userName?? String password) {
if(userName.length() <= 4 || userName.length() > 8 )
returnfalse;
if(password.length() <= 4 || password.length() > 8 )
returnfalse;
if(userName.contains("@"))
returnfalse;
if(password.contains("*"))
returnfalse;
returntrue;
}
}
????1?????Junit???????????????????
???????????
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
importstaticorg.junit.Assert.assertEquals ;
import sample.junit.code.UserAccess;
/*
* JUnit - Parameter test sample
*/
@RunWith(Parameterized.class)
publicclassJunitSample {
privateString user ;
privateString pwd ;
privateboolean expected ;
@Parameters
publicstaticCollection dataGenerate(){
returnArrays.asList(newObject[][]{
{"user01"??"123456"??true}??
{"user02"??"123456"??true}??
{"user03"??"12345678"??true}
});
}
publicJunitSample(String user??String pwd??boolean expected){
this.user = user;
this.pwd = pwd;
this.expected = expected;
}
@Test
publicvoidtestAccessCheck(){
assertEquals(expected??UserAccess. accessCheck(user?? pwd));
}
}
???????н???????????
????2???????????????(Feed4Junit)
????Feed4JUnit ??????????????????????????????????°汾http://sourceforge.net/projects/feed4junit/files/
????Feed4JUnit ????????????????????????? – ??? (CSV ???? Excel )???????????????????
????????????÷????? Feed4JUnit ????????????????? Feeder.class??????????????????????????????????д?????????????????????????????????????????????
????1)???????????????????????? @RunWith(Feeder.class) ??
????2)???????? @Test ???????????????????
????3)??? @Source ???????????????????????
????2.1 ????????(excel??csv????)
????1)??????????????′??? data.xls ??data.csv?????????????л?????????????????й????в??????????????
????2)?????????????????????????????????????? @Source("Data.xls")??Excel ?е??????????????л?????????????????????????λ?????????????????????????λ??????????????????塣????????е? user ?е??????????????????????????????У?pw ?е??????????????????????????????????????й????У??????? Excel ????ж?????(????????)?????????λ?????????????????????(??а?????????????)??????У?????????? Excel ?е?????н?????????????????????? Java ?е?????????????????????????????????????С??????????????????????????????λ?ò?????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11