程序包 org.junit.rules

类 TemporaryFolder

  • 所有已实现的接口:
    TestRule

    public class TemporaryFolder
    extends ExternalResource
    The TemporaryFolder Rule allows creation of files and folders that should be deleted when the test method finishes (whether it passes or fails). Whether the deletion is successful or not is not checked by this rule. No exception will be thrown in case the deletion fails.

    Example of usage:

     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");
          // ...
         }
     }
     
    从以下版本开始:
    4.7