我在这里遇到了一个奇怪的问题......
我有一个 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 时遇到完全相同的问题......
我怎样才能解决这个问题以使其正常工作?
最佳答案
您应该尝试禁用防病毒保护。
我遇到了同样的问题,禁用卡巴斯基后一切正常。
关于java - JUnit Rule TemporaryFolder 任意抛出 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10195128/