开发者

Tests fail in Jenkins

I have a maven project which is build and tested in Jenkins. On my local machine the tests run successful but in Jenkins a file cannot be loaded which is needed by the test. I use this.getClass.getResourceAsStream("testfile.dat") to load the resource. It 开发者_如何学运维seems that Jenkins doesn't copy the resource files to the directory the tests are running in. Is that a maven problem? How do I advice Jenkins/Maven to copy the resources to the test classpath?


Put your test resources in the src/test/resources tree of your Maven project. Maven will ensure that they are on the classpath when your tests are run, and hence that they can be found using getResourceAsStream(...).


When you are using getResourceAsStream with a string argument which does not specify a package (as in your example "testfile.dat"), the resource must be located in exactly the same package (aka folder) as the Class object you are calling the getResourceAsStream method on. You should check if both, the class and it's resources are really in the same package.

You might want to have a look at the target folder Maven generates when packaging your project, you can find out where your resources end up there.


I had a similar problem, but I did not want to move the resources to src/test/resources for various reasons. Nevertheless I could solve the problem by adding explicitly all subfolders to the pom.xml as the following snippet shows:

<build>
  <resources>
    <resource>
        <directory>myFolder/subFolder1</directory>
    </resource>
    <resource>
        <directory>myFolder/subFolder2</directory>
    </resource>
    <resource>
        <directory>myFolder/subFolder3</directory>
    </resource>
  </resources>
    [....]
</build>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜