gpt4 book ai didi

java - 为什么我会看到 "the temporary folder has not yet been created"消息?

转载 作者:行者123 更新时间:2023-12-02 04:23:56 26 4
gpt4 key购买 nike

在以下代码中,我在 getRoot() 调用中收到异常 java.lang.IllegalStateException:尚未创建临时文件夹

我找到了StackOverflow post根据该代码应该可以工作。另外,我注意到,如果我在 getRoot() 调用之前添加 temporaryFolder.create();,则代码可以正常工作。

    public class MainTest extends TestCase {

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test
public void testMethod() throws Exception {
File folder = temporaryFolder.getRoot();
}
}

为什么会发生这种情况?

最佳答案

您正在混合 JUnit 3 (junit.framework.) 和 JUnit 4 (org.junit.) 代码。如果您仅使用 JUnit 4,该问题应该会消失。

删除extends TestCase(它们很简单,不需要,因为您的测试是用@Test注释的)。

关于java - 为什么我会看到 "the temporary folder has not yet been created"消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30642962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com