|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.junit.rules.ExternalResource
org.junit.rules.TemporaryFolder
public class TemporaryFolder
The TemporaryFolder Rule allows creation of files and folders that are guaranteed to be deleted when the test method finishes (whether it passes or fails):
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 Summary | |
|---|---|
TemporaryFolder()
|
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class org.junit.rules.ExternalResource |
|---|
apply |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TemporaryFolder()
| Method Detail |
|---|
public void create()
throws IOException
IOException
public File newFile(String fileName)
throws IOException
IOExceptionpublic File newFolder(String folderName)
public File getRoot()
public void delete()
Rule
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||