gpt4 book ai didi

java - Junit 4.11 TemporaryFolder 构造函数与 java.io.File

转载 作者:行者123 更新时间:2023-12-01 12:45:33 26 4
gpt4 key购买 nike

我正在尝试这样做。它在 eclipse 中工作正常,但在 maven 中给出错误。

示例代码

File baseFolder=new File("C:\BASE_FOLDER");
temporaryFolder = new TemporaryFolder(baseFolder);


//Error in maven
[ERROR] symbol : constructor TemporaryFolder(java.io.File)
[ERROR] location: class org.junit.rules.TemporaryFolder

任何链接或提示都会有帮助。谢谢。

完全错误:

symbol  : constructor TemporaryFolder(java.io.File)
location: class org.junit.rules.TemporaryFolder

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure

最佳答案

因为 TemporaryFolderTestRule ,您可以将它与 @Rule 注释一起使用。来自 Javadoc :

public static class HasTempFolder {
@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Test
public void testUsingTempFolder() throws IOException {
File createdFile = folder.newFile("myfile.txt");
File createdFolder = folder.newFolder("subfolder");
// ...
}
}

或者如果您想指定位置:

File baseFolder = new File("C:\BASE_FOLDER");
@Rule
public TemporaryFolder folder = new TemporaryFolder(baseFolder);

关于java - Junit 4.11 TemporaryFolder 构造函数与 java.io.File,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24734591/

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