??????????????д???в???????飬???·???????о??????????????????????????????????????????????????????????ν??????????????ν????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/