My tests require the extraction of data from a file. I want to pass the location of the file together with some other parameters to the Junit tests.
Can this be done via commandline arguments? If not, what is the recommended way to do that? Creating a configuration file or environment variables?
It is not recommended with junit to read variables out of the config and to use them for the tests, because then the tests are no longer based on the code but partly on your config.
You should rather hard code the variables. An example from one of my projects:
@Test
public void testIfEmailValidatorReturnsCorrectValue() {
Validators validator = Validators.getInstance();
Assert.assertFalse(validator.isMail(""));
Assert.assertFalse(validator.isMail("test"));
Assert.assertFalse(validator.isMail("test@mail"));
Assert.assertFalse(validator.isMail("test@mail:de"));
Assert.assertFalse(validator.isMail("test@test@mail.de"));
Assert.assertFalse(validator.isMail("testmail.de"));
Assert.assertFalse(validator.isMail("test@mail.d$e"));
Assert.assertTrue(validator.isMail("test@mail.de"));
Assert.assertTrue(validator.isMail("testASD01@Ma1l.com"));
Assert.assertTrue(validator.isMail("testASD01@sub.Ma1l.com"));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.