我在这里面临一个奇怪的问题......JUnit的规则TemporaryFolder随意抛出IOException
我实现了一些测试JUnit的。这个类看起来如下:
public class MyTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Test
public void myTest1() throws IOException {
String destinationPath = folder.newFile("destination1.txt").getPath();
// Do things
}
@Test
public void myTest2() throws IOException {
String destinationPath = folder.newFile("destination2.txt").getPath();
// Do things
}
@Test
public void myTest3() throws IOException {
String destinationPath = folder.newFile("destination.txt").getPath();
// Do things
}
}
这个测试类用于工作在我以前的环境,仍然在Continuum中。
然而,从Eclipse的无启动时,一些或所有的测试随意抛出一个IOException
如:
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at org.junit.rules.TemporaryFolder.newFile(TemporaryFolder.java:53)
at MyTest.myTest2(MyTest.java:50)
我有运行JUnit 4.9或JUnit的4.10完全相同的问题...
我该如何解决这个问题才能正常工作?
这应该工作。你使用哪个'Runner'来运行测试?它们是并发的吗?您可能需要调试更多内容,即查看'folder'变量,以便在出现问题时查看它指向的位置。 – 2012-04-17 18:38:35
你能说出你在测试中做什么吗?你正在写文件吗?此外,你有Windows索引运行? – 2012-05-30 06:45:43
是的程序的目的是处理数据和写入文件作为输出。没有Windows索引正在运行。 – 2012-05-30 07:10:23