jeudi 17 décembre 2020

Error: the temporary folder has not yet been created

When I run the code below, I get:

java.lang.IllegalStateException: the temporary folder has not yet been created at org.junit.rules.TemporaryFolder.getRoot(TemporaryFolder.java:145) at org.junit.rules.TemporaryFolder.newFolder(TemporaryFolder.java:94)

Why am I getting this error? This should be as basic as you can get with TemporaryFolder. I litteraly just copy pasted it from this SO answer.

    package unitTests;
    
    import org.junit.Rule;
    import org.junit.jupiter.api.Test;
    import org.junit.rules.TemporaryFolder;
    
    import java.io.File;
    
    import static org.junit.jupiter.api.Assertions.assertEquals;
    
    public class testTempFolder {
    
        @Rule
        public final TemporaryFolder temporaryFolder = new TemporaryFolder();
    
        @Test
        public void test() throws Exception {
            File child = temporaryFolder.newFolder("grandparent", "parent", "child"); // <-- this line fails
    
            assertEquals("child", child.getName());
            assertEquals("parent", child.getParentFile().getName());
            assertEquals("grandparent", child.getParentFile().getParentFile().getName());
            System.out.println(child.getAbsolutePath());
        }
    }

build.gradle

dependencies {
    implementation 'com.google.code.gson:gson:2.8.6'

    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.0'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' // Added by intellij by default
    testRuntimeOnly    'org.junit.jupiter:junit-jupiter-engine'    // Added by intellij by default

    testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '2.2'

Aucun commentaire:

Enregistrer un commentaire