Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I see "the temporary folder has not yet been created" message?

Tags:

java

junit

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?

like image 925
traveh Avatar asked Jun 04 '15 11:06

traveh


1 Answers

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).

like image 113
mp911de Avatar answered Sep 27 '22 21:09

mp911de