JUnit Rule TemporaryFolder任意抛出IOException

Jea*_*art 9 java junit ioexception junit4

我在这里遇到一个奇怪的问题......

我有一个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
    }
}
Run Code Online (Sandbox Code Playgroud)

这个测试类曾经在我之前的环境中工作,但仍然在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)
Run Code Online (Sandbox Code Playgroud)

我有完全相同的问题运行JUnit 4.9或JUnit 4.10 ...

我该如何解决它以使其正常工作?

小智 1

您应该尝试禁用防病毒保护。

我遇到了同样的问题,禁用卡巴斯基后一切正常。