【发布时间】:2012-04-17 16:22:24
【问题描述】:
我在这里遇到了一个奇怪的问题......
我有一个执行一些测试的 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变量也可以查看问题发生时它指向的位置。 -
你能说一下你在测试中做了什么吗?你在写文件吗?另外,您是否正在运行 Windows 索引?
-
是的,该程序的目的是处理数据并将文件写入输出。没有 Windows 索引正在运行。
标签: java junit junit4 ioexception