我有一个Java项目,当我从命令行构建mvn clean install
命令时,它会生成一个输出目标文件夹。如何使测试类从目标/而不是目标/测试类读取数据Java
我有一个JUnit测试类,它从此目标文件夹中获取测试数据。直接运行此测试类(右键单击Testclass.java>运行方式> Junit测试)可以正常工作,因为目标文件夹已经生成。
但是当我做一个mvn clean
(它清除了目标文件夹和我的测试数据),然后做一个mvn clean install
我得到一个测试失败。由于测试正试图从目标/测试类/ PDF内容从目标/ PDF内容阅读,而不是
我怎样才能让我的TestClass从target/
而不是target/test-classes
读取测试数据?
编辑:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>unpack and rename content</id>
<phase>process-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
</properties>
<source>
import com.cg.fs.common.FileUtil
import com.cg.fs.common.ZipUtil
import com.cg.fs.common.StringUtil
com.services.fs.common.logging.LoggerFactory.setLogger("com.services.fs.common.logging.SystemOutLogger")
com.services.fs.common.logging.FSLogger.setMinimal(true)
buildHelper = new BuildHelper()
output = new File("target")
pdfContent = new File("target/pdf-content")
// unzip tt intermediate thing
List ttZip = FileUtil.discoverFiles(output, true, "production-content-.*\\.zip")
assert ttZip.size() == 1, "Did not find expected number of content zip " + ttZip.size()
println "Unzipping " + ttZip.get(0)
ZipUtil.unzipToDisk(ttZip.get(0))
// move it to pdf content
List content = FileUtil.discoverDirectories(output, "production-content-.*-intermediate", true)
assert tContent.size() == 1, "Did not find expected number of contents " + tContent.size()
println "Moving " + tContent.get(0) + " to " + pdfContent
success = FileUtil.copy(tContent.get(0), pdfContent)
assert success, "Could not copy content"
// move pdf content
List fpsContent = FileUtil.discoverDirectories(output, “ls-production-content.*", true)
assert fpsContent.size() == 1, "Did not find expected number of ls contents " + fpsContent.size()
println "Moving " + fpsContent.get(0) + " to target/pdf-content"
success = FileUtil.copy(fpsContent.get(0), pdfContent)
assert success, "Could not copy pdf content"
// rename to not be unsupported
List unsupportedDirs = FileUtil.discoverDirectories(pdfContent, "_unsupported_.*", true)
println "Renaming _unsupported content: " + unsupportedDirs
for (File file : unsupportedDirs) {
file.renameTo(new File(file.getParentFile(), file.getName().replace("_unsupported_", "")))
}
</source>
</configuration>
我与maven斗争,我避免搞乱我的pom。因此,在'<! - 放置测试资源的路径 - > '我究竟会放什么? SRC /测试/资源? –
@arabian_albert好的,我编辑了。你可以离开它。如果您想要指定包中的资源,则只需要它。默认情况下,它将位于类路径的根目录下。 – Tunaki
说我确实希望它在指定的包中,我会把什么放在targetPath下?我想拥抱maven我只是不认为我理解正确 –