3

I've been trying to get Jenkins to display a JUnit report of a sample js project which i am testing with QUnit. I have literally scoured the internet for bits and pieces and so far, Running QUnit tests with Jenkins and Apache Ant? is the most helpful post that i have found.

I can confirm that:

  • The user has sufficient privileges to write to disk
  • PhantomJS works headless from the shell when i write something along the lines of:

        [user@myserver PhantomJS]$ phantomjs phantomjs-runner/runner.js web/index.html 
    

    And shows:

    Took 8ms to run 6 tests. 6 passed, 0 failed.

  • Qunit does work and provides test results when executed in a browser

Still i cannot get the report.xml to generate in order to feed it into Jenkins. Below is the target i have added to my build.xml file:

    <target name="qunit" description="runs QUnit tests using PhantomJS">
    <!-- QUnit Javascript Unit Tests -->
    <echo message="Executing QUnit Javascript Unit Tests..."/>
    <apply executable="/usr/local/CI/phantomjs/bin/phantomjs" >
        <arg value="/usr/local/CI/phantomjs-runner/runner.js" />
        <arg line="--qunit /usr/local/CI/jenkins/workspace/PhantomJS/web/js/qunit-1.17.1.js --tests /usr/local/CI/jenkins/workspace/PhantomJS/web/index.html --junit /usr/local/CI/jenkins/workspace/PhantomJS/test-results/report.xml" />
        <fileset dir="${basedir}/web/" includes="/js/prettydate.js" />
        <srcfile/>
    </apply>
    <echo message="Tests complete..."/>
</target>

Compiling the project in Jenkins gives me the following output:

? PhantomJS/result.xml ? PhantomJS/test-results Using locally configured password for connection to :pserver:user@server:/cvsroot cvs rlog -S -d18 Feb 2015 15:49:54 +0000<18 Feb 2015 15:51:40 +0000 QUnit_Jenkins [PhantomJS] $ /usr/local/CI/ant/bin/ant qunit Buildfile: /usr/local/CI/jenkins/workspace/PhantomJS/build.xml

qunit: [echo] Executing QUnit Javascript Unit Tests... [echo] Tests complete...

BUILD SUCCESSFUL Total time: 0 seconds Recording test results Test reports were found but none of them are new. Did tests run? For example, /usr/local/CI/jenkins/workspace/PhantomJS/test-results/report.xml is 4 hr 18 min old

Build step 'Publish JUnit test result report' changed build result to FAILURE Finished: FAILURE

As you may notice, jenkins can't find an updated report.xml file because there simply isn't one getting generated.

Can you observe any mistakes in my build.xml? If not, any ideas, hints that would assist me in getting the result.xml file generated?

Community
  • 1
  • 1
Cpn. Soju
  • 61
  • 5
  • Hmm... no idea, but interested to see if you get it fixed. – Jordan Kasper Feb 18 '15 at 19:40
  • i think your report is not generated in path '/usr/local/CI/jenkins/workspace/PhantomJS/test-results/report.xml ' from jenkins.you better have a look on it. Do below things to get rid of the error. after build, in build steps ->add execute shell with inputs `touch /usr/local/CI/jenkins/workspace/PhantomJS/test-results/report.xml` – DevD Feb 19 '15 at 10:10
  • also make sure that you clean up your workspace before build – DevD Feb 19 '15 at 10:15
  • touch will create an empty file which will not contain any XML-JUnit reports i'm afraid, so that will not work – Cpn. Soju Feb 24 '15 at 16:35

1 Answers1

2

I have found a solution to my answer by taking the following steps:

1) added <script src="js/qunit-reporter-junit.js"></script> as it is required to generate the report. Ensure you also have the qunit.js library included also. I used qunit-1.17.1.js

2) I placed the following code in the html file that tests my js code:

<script>
QUnit.jUnitReport = function(report) {
   console.log(report.xml)
      };
</script>

3) I added the Ant code in my build.xml file:

    <target name="build" description="runs QUnit tests using PhantomJS">
        <!-- Clean up output directory -->
        <delete dir="./build/qunit"/>
        <mkdir dir="./build/qunit"/>
        <!-- QUnit Javascript Unit Tests -->
        <echo message="Executing QUnit Javascript Unit Tests..."/>
        <exec executable="/usr/local/CI/phantomjs/bin/phantomjs" output="./build/qunit/qunit-results.xml">
            <arg value="/usr/local/CI/phantomjs-runner/runner-muted.js"/>
            <arg value="./web/index.html"/>
        </exec>
    </target>

You will observe that i changed the name of runner.js to runner-muted.js This is so, because i have made changes to runner.js to not include its output to the xml file, as this makes it unreadable by jenkins. To do so:

  1. cp /usr/local/CI/phantomjs-runner/runner.js /usr/local/CI/phantomjs-runner/runner-muted.js
  2. Find and comment out console.log occurrences found under QUnit.done and QUnit.testDone to mute the runner from displaying its own test run results.
  3. Ensure that in Jenkins you have selected the correct path to the generated xml file.

I hope this helps any of you trying to get it to work

Cpn. Soju
  • 61
  • 5