我在这里遇到了一个奇怪的问题...
我有一个实现了几个测试的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时...
我该如何修复它,使其正常工作?