程序包 org.junit.rules
类 TemporaryFolder
- java.lang.Object
- org.junit.rules.ExternalResource
- 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
构造器概要
构造器 构造器 说明 TemporaryFolder()
TemporaryFolder(File parentFolder)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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()
Returns a new fresh file with a random name under the temporary folder.File
newFile(String fileName)
Returns a new fresh file with the given name under the temporary folder.File
newFolder()
Returns a new fresh folder with a random name under the temporary folder.File
newFolder(String folder)
Returns a new fresh folder with the given name under the temporary folder.File
newFolder(String... folderNames)
Returns a new fresh folder with the given name(s) under the temporary folder.从类继承的方法 org.junit.rules.ExternalResource
apply
构造器详细资料
TemporaryFolder
public TemporaryFolder()
TemporaryFolder
public TemporaryFolder(File parentFolder)
方法详细资料
before
protected void before() throws Throwable
从类复制的说明:ExternalResource
Override to set up your specific external resource.- 覆盖:
before
在类中ExternalResource
- 抛出:
Throwable
- if setup fails (which will disableafter
after
protected void after()
从类复制的说明:ExternalResource
Override to tear down your specific external resource.- 覆盖:
after
在类中ExternalResource
create
public void create() throws IOException
for testing purposes only. Do not use.- 抛出:
IOException
newFile
public File newFile(String fileName) throws IOException
Returns a new fresh file with the given name under the temporary folder.- 抛出:
IOException
newFile
public File newFile() throws IOException
Returns a new fresh file with a random name under the temporary folder.- 抛出:
IOException
newFolder
public File newFolder(String folder) throws IOException
Returns a new fresh folder with the given name under the temporary folder.- 抛出:
IOException
newFolder
public File newFolder(String... folderNames) throws IOException
Returns a new fresh folder with the given name(s) under the temporary folder.- 抛出:
IOException
newFolder
public File newFolder() throws IOException
Returns a new fresh folder with a random name under the temporary folder.- 抛出:
IOException