In the following code I get the exception java.lang.IllegalStateException: the temporary folder has not yet been created
at the getRoot()
call.
I found a StackOverflow post according to which this code should work. Also, I noticed that if I add temporaryFolder.create();
before the getRoot()
call, the code works fine.
public class MainTest extends TestCase {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void testMethod() throws Exception {
File folder = temporaryFolder.getRoot();
}
}
Why is this happening?
You are mixing JUnit 3 (junit.framework.) and JUnit 4 (org.junit.) code. The problem should disappear if you are using JUnit 4 only.
Remove extends TestCase
(they are simple not needed, because your tests are annotated with @Test
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With