temporaryFolder.newFolder(String... folderNames)
将整个层次结构作为参数:
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void test() throws Exception {
File child = temporaryFolder.newFolder("grandparent", "parent", "child"); //...
assertEquals("child", child.getName());
assertEquals("parent", child.getParentFile().getName());
assertEquals("grandparent", child.getParentFile().getParentFile().getName());
System.out.println(child.getAbsolutePath());
}
它通过了测试和打印:
/var/folders/.../T/junit8666449860303204067/grandparent/parent/child