I am trying to write a test that loads different properties files from String array. But the code keeps throwing a null pointer exception, any ideas please?
@RunWith(value = Parameterized.class)
public class AllTests
{
private static String text;
private static Properties props;
public AllTests(String text)
{
AllTests.text= text;
}
@Parameters
public static List<String[]> data()
{
String[][] data = new String[][] { { "test.properties" }};
return Arrays.asList(data);
}
@BeforeClass
public static void setup()
{
props = new Properties();
try
{
//load a properties file
props.load(new FileInputStream(text));
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
@Test
public void test()
{
System.out.println(text);
}}
I did some further investigation and discovered the @Test stub works but the @BeforeClass returns null, can I not use the parameters in the setup?
@RunWith(value = Parameterized.class)
public class AllTests
{
private static String client;
public AllTests(String client)
{
AllTests.client = client;
}
@Parameters
public static Collection<Object[]> data()
{
Object[][] data = new Object[][] { { "oxfam.properties" }};
return Arrays.asList(data);
}
@BeforeClass
public static void setup()
{
System.out.println(client);
}
@Test
public void test()
{
System.out.println(client);
}}