How to use temporary folder in Junit ( with example )

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). The TemporaryFolder is a test helper belongs to one of the Junit rules.
public static class HasTempFolder {
public TemporaryFolder folder= new TemporaryFolder();

public void testUsingTempFolder() throws IOException {
File createdFile= folder.newFile("myfile.txt");
File createdFolder= folder.newFolder("subfolder");
assertTrue( createdFolder.exists() );


Popular posts from this blog

Check MySQL query history from command line

Fixed: ImportError: No module named