java - JUnit Rule TemporaryFolder 任意抛出 IOException

标签 java junit junit4 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 时遇到完全相同的问题......

我怎样才能解决这个问题以使其正常工作?

最佳答案

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

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

关于java - JUnit Rule TemporaryFolder 任意抛出 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10195128/

相关文章:

java - 如何计算两个 vector 的余弦相似度?

intellij-idea - 通过 build.gradle 传递标签,而不是通过 RunCukesSpec

java - junit中如何判断一个方法是否被重写了?

java - 我如何重构这些包装器方法以摆脱重复的代码?

java - Android:在服务内的定时器任务处更新 GUI

java - 使用 Kotlin 使用 OkHttp 发送 JSON 数据

java - 解析 JUnit 测试中的 Spring @Value 表达式

java - 在 cucumber junit中发现没有后端

java - JUnit 测试 SQL 查询

xml - 有没有办法以 junit.xml 格式生成 Jest/Istanbul 覆盖率报告