Tests failed in jenkins

I have a maven project that is being built and tested in Jenkins. On my local machine, the tests are successful, but the file cannot be loaded in Jenkins, which is necessary for the test. I use this.getClass.getResourceAsStream("testfile.dat")to load a resource. It seems that Jenkins is not copying the resource files to the directory in which the tests are running. Is this a problem with maven? How do I recommend Jenkins / Maven to copy resources to a test path?

+3
source share
3 answers

Put your test resources in the tree of src/test/resourcesyour Maven project. Maven will ensure that they are on the way to the classes when you run your tests, and therefore can be found with getResourceAsStream(...).

+5

getResourceAsStream , ( "testfile.dat" ), (aka folder) Class , getResourceAsStream. , .

, target, Maven , , .

0

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

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

All Articles