You are assigning to a local variable here:
Path file1 = Files.createTempFile(testFolder, "test-", ".txt");
do this instead:
file1 = Files.createTempFile(testFolder, "test-", ".txt");
Question
I have code like
private static Path file1; // reference file
@BeforeClass
public static void setUpBeforeClass()
{
Path file1 = Files.createTempFile(testFolder, "test-", ".txt");
}
@Test
public void testIdentical()
{
assertNotNull(file1); // fails
}
But file1
is null. I have been searching for answers to this problem, and while the issues are similar, no-one ever seams to explain clearly what exactly is going on, or how to do what I want to do: which is for file1
to not be null.
I am doing what https://github.com/junit-team/junit/wiki/Test-fixtures seems to indicate is correct, but I am not getting the results I expect.
Solution
You are assigning to a local variable here:
Path file1 = Files.createTempFile(testFolder, "test-", ".txt");
do this instead:
file1 = Files.createTempFile(testFolder, "test-", ".txt");