I try to use FileParameters annotation of JUnitParamsRunner. I cannot give null to a variable. The code and test file is below.
@RunWith(JUnitParamsRunner.class)
public class PasswordCheckerFileParameterizedTest {
@Test
@FileParameters("src/test/resources/testScenarios.csv")
public void checkPasswordIsValid_checkMultipleCase(String password,boolean expectedResult){
PasswordChecker passwordChecker = new PasswordChecker();
assertEquals(expectedResult,passwordChecker.checkPasswordIsValid(password));
}
}
testScenarios.csv
,false
sD1.,false
ssfdsdfsdf234.,false
SEWERWER234.,false
ssfdsdfsdSDFSDF.,false
ssfdsdfsdSDFSDF3234,false
ssfdsdfsdSDFSDF23.,true
This does not work by default since
FileParametersusesIdentityMapperto map lines in the file to parameters and that works as if you used the@Parameters({"aaa,bbb", "ccc,ddd"}syntax in which you cannot provide anullvalue - writingnullwill give you a String saying"null".You can however provide your own mapper by means of
FileParameters#mapper. It has to return a mappedObject[][](same format as if you used a method parameter provider for@Parameters(method = ...)). Then you need to decide in what way you'll marknullin your file.A sample mapper that treats the string
"xxx"as anullmarker would look like this:Usage:
/test.csv:Prints