public class TemporaryFolder extends ExternalResource
public static class HasTempFolder {
@Rule
public TemporaryFolder folder= new TemporaryFolder();
@Test
public void testUsingTempFolder() throws IOException {
File createdFile= folder.newFile("myfile.txt");
File createdFolder= folder.newFolder("subfolder");
// ...
}
}
| Constructor and Description |
|---|
TemporaryFolder() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after()
Override to tear down your specific external resource.
|
protected void |
before()
Override to set up your specific external resource.
|
void |
create()
for testing purposes only.
|
void |
delete()
Delete all files and folders under the temporary folder.
|
File |
getRoot() |
File |
newFile(String fileName)
Returns a new fresh file with the given name under the temporary folder.
|
File |
newFolder(String folderName)
Returns a new fresh folder with the given name under the temporary folder.
|
applyprotected void before()
throws Throwable
ExternalResourcebefore in class ExternalResourceThrowableprotected void after()
ExternalResourceafter in class ExternalResourcepublic void create()
throws IOException
IOExceptionpublic File newFile(String fileName) throws IOException
IOExceptionpublic File newFolder(String folderName)
public File getRoot()
public void delete()
Rule