junit 测试应该使用 main/resources [英] junit test should use main/resources
问题描述
我在使用 maven 和 JUnit 测试时遇到问题.
I have a problem with maven and JUnit testing.
我在 src/main/resources 中有一些文件,在运行 junit 测试时我想要这些文件.只有一个设置略有不同的测试特定文件才能覆盖相应的文件.所以我的想法是给这个测试文件与主文件相同的名称,并将它的文件放在 src/test/resources 下与主文件相同(对应)的地方.但是现在我遇到了问题,我无法使用 src/main/resources.js 中的所有其他文件.
I have some files in src/main/resources and when running junit tests I want to these files. Only one test specific file with slightly different settings should overrule a corresponding file. So my idea was to give this test-file the same name like the main-file and put it file under src/test/resources at the same (corresponding) place like the main-file. But now I have the problem, that I cant use all the other files from src/main/resources.
我认为他们 junit test 会在运行时将它们默认复制到 target/test-classes/由来自 src/test/resources 的文件组成,但事实并非如此.只有来自 src/test/resources 的文件,没有其他文件.
I thought they junit test would coppy them default into target/test-classes/ when running ernriced by the files from src/test/resources, but it doesnt. There is only the file from src/test/resources and not other.
感谢您的任何想法,我该如何解决这个问题.
Thanks for any ideas, how I could solf this problem.
这里是我如何尝试访问文件的示例
here an example how I try to access the files
'
@BeforeClass
public static void globalSetUp() throws NamingException, SQLException {
System.setProperty("solr.solr.home", "/solr/");
cores = new CoreContainer(
"/home/foo/workspace/reporting/target/test-classes/solr");
cores.load();
server = new EmbeddedSolrServer(cores, "reporting");
loadDriver();
connection = createAndConnectToDB();
createDBSchema();
}
'
推荐答案
问题出在 pom.xml 中./main/resources 不是 testResource.
The problem was in pom.xml. /main/resources was not as testResource.
这是解决我的问题的代码片段:
Here's the snippet that solved my problem:
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/main/resources</directory>
</testResource>
</testResources>
</build>
这篇关于junit 测试应该使用 main/resources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!