Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
687 views
in Technique[技术] by (71.8m points)

unit testing - junit test should use main/resources

I have a problem with maven and JUnit testing.

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.

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();

}

'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...