Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-29359

"unit test" code on the Wiki page fails with Exception when "./target" folder does not exist.

      I tried sample code at the top of this page: https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test

      {{

      @Rule public JenkinsRule j = new JenkinsRule();
      @Test public void first() throws Exception

      { FreeStyleProject project = j.createFreeStyleProject(); project.getBuildersList().add(new Shell("echo hello")); FreeStyleBuild build = project.scheduleBuild2(0).get(); System.out.println(build.getDisplayName() + " completed"); // TODO: change this to use HtmlUnit String s = FileUtils.readFileToString(build.getLogFile()); assertThat(s, contains("+ echo hello")); }}

      it failed with exception when it could not create a folder inside "./target" because "./target" does not exist in my project folder.

      java.lang.Exception: Failed to initialize exploded war
      at org.jvnet.hudson.test.WarExploder.getExplodedDir(WarExploder.java:49) at org.jvnet.hudson.test.JenkinsRule.createWebServer(JenkinsRule.java:578) at
      Caused by: java.io.FileNotFoundException: C:\projects\jenkins-publisher-plugin\.\target\jenkins-for-test.exploding (The system cannot find the path specified)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
      at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
      at org.jvnet.hudson.test.WarExploder.explode(WarExploder.java:99)
      at org.jvnet.hudson.test.WarExploder.<clinit>(WarExploder.java:58)

          [JENKINS-29359] "unit test" code on the Wiki page fails with Exception when "./target" folder does not exist.

          Oleg Nenashev added a comment -

          Yes, we expect that target exists after the build. O which core version does your plugin depend?

          Oleg Nenashev added a comment - Yes, we expect that target exists after the build. O which core version does your plugin depend?

          Alex Java added a comment -

          my plugin depends on Jenkins Core 1.580.3
          here is the source code: https://github.com/alexeyOnGitHub/jenkins-publisher-plugin/blob/ask-integration-testing/src/test/java/org/jenkinsci/plugins/jpp/BuildRunListenerIT.java
          I do not use Maven for builds (which would create "target" folder). I use Gradle instead. also, I ran this test from IDEA, which would not necessarily create "target" folder either.

          Alex Java added a comment - my plugin depends on Jenkins Core 1.580.3 here is the source code: https://github.com/alexeyOnGitHub/jenkins-publisher-plugin/blob/ask-integration-testing/src/test/java/org/jenkinsci/plugins/jpp/BuildRunListenerIT.java I do not use Maven for builds (which would create "target" folder). I use Gradle instead. also, I ran this test from IDEA, which would not necessarily create "target" folder either.

          Daniel Beck added a comment -

          This looks a lot like JENKINS-26331 and been fixed in core as https://github.com/jenkinsci/jenkins/commit/1fae8c072a1e8da360cd10dca8b82d1cd1b00968.

          A workaround in the Gradle JPI plugin is https://github.com/daspilker/gradle-jpi-plugin/blob/master/src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiExtension.groovy#L131...L137 but it doesn't appear to work on your system. Therefore reassigning to Gradle JPI plugin.

          Daniel Beck added a comment - This looks a lot like JENKINS-26331 and been fixed in core as https://github.com/jenkinsci/jenkins/commit/1fae8c072a1e8da360cd10dca8b82d1cd1b00968 . A workaround in the Gradle JPI plugin is https://github.com/daspilker/gradle-jpi-plugin/blob/master/src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiExtension.groovy#L131...L137 but it doesn't appear to work on your system. Therefore reassigning to Gradle JPI plugin.

          The workaround in the Gradle JPI plugin only works when running a Gradle build. If you checkout the project with an IDE and try to run the tests, it will fail because older versions of the test harness do not create the folder.

          The fix by integer is available in 1.592 or later:
          https://github.com/jenkinsci/jenkins/commit/9aaeb0a3f248f8f7280e6e010c695340eee721d7

          Daniel Spilker added a comment - The workaround in the Gradle JPI plugin only works when running a Gradle build. If you checkout the project with an IDE and try to run the tests, it will fail because older versions of the test harness do not create the folder. The fix by integer is available in 1.592 or later: https://github.com/jenkinsci/jenkins/commit/9aaeb0a3f248f8f7280e6e010c695340eee721d7

          Alex Java added a comment -

          alright, it's all clear. thanks a lot for your help.

          Alex Java added a comment - alright, it's all clear. thanks a lot for your help.

          Alex Java added a comment -

          adding a link to JIRA JENKINS-26331

          Alex Java added a comment - adding a link to JIRA JENKINS-26331

            daspilker Daniel Spilker
            alskor Alex Java
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: