Karma - JUnitReport - ANT: empty report - ant

I have some AngularJS E2E tests that run normally and have reporters set to:
...
reporters = ['junit'];
junitReporter = {
outputFile : 'test/e2e-results.xml',
suite : 'e2e'
};
...
The reports xml file is generated and contains a hierarchy of testsuites->testsuite->testcases....
I'm trying to use ANT to generate HTML reports.
<junitreport todir="./reports">
<fileset dir="./reports">
<include name="e2e-results.xml"/>
</fileset>
<report format="frames" todir="./report/html"/>
</junitreport>
The HTML files are generated properly, but all values in the tables are empty, 0 Tests, 0 Failures etc...
What am I doing wrong?
Thanks in advance

Related

Translate ant script that creates a jar file into sbt

I have an ant file called jarPLCExample.xml that takes some class files and produces a jar file. What would the <jar> tag section of this file look like in sbt?
<project name="jar_myplc" default="jar_myplc" basedir=".">
<property file="../resources/v2.properties"/>
<property name="dist.dir" value="C://where_jar_files_go/lib"/>
<property name="dist.file" value="${dist.dir}/PLC.jar"/>
<target name="jar_myplc">
<tstamp>
<format property="TODAY" pattern="dd/MM/yyyy hh:mm aa" locale="au"/>
</tstamp>
<delete file="${dist.file}" quiet="true"/>
<jar destfile="${dist.file}">
<fileset dir="${v2.out.root}" includes="com/companyname/server/applic/**/*.class"/>
<fileset dir="${v2.out.root}" includes="com/companyname/common/utils/SeaDef*.class"/>
</jar>
<copy file="${dist.file}" todir="C:/deploy"/>
</target>
sbt-assembly no good for this as it seems you can exclude and include jars, but not source file packages and source file names as needs to be done here.
Obviously important to 'go with the flow': I expect sbt will want to compile from source, so no need to explicitly use .class files as the ant task above does.
I already have a build.sbt in the base directory, and it would be sensible to call this file jarPLCExample.sbt, but I don't know how to get sbt to load one particular file. So instead I will have two projects in the one file and manually set the current project by changing their order. (As they both have the same key the second one seems to overwrite the first one - the projects command will always show only one project).
This answer has two shortcomings. It only includes the applic directory rather than all directories (recursively) below applic. Also it will pick up all SeaDef*.class, no matter which directories they are in.
def filter3(file: File, greatGrandParent:String, grandParent:String, parent:String, excludes:List[String]):Boolean = {
file.getParentFile.getName == parent &&
file.getParentFile.getParentFile.getName == grandParent &&
file.getParentFile.getParentFile.getParentFile.getName == greatGrandParent &&
!excludes.exists( _ == file.getName)
}
/*
* <fileset dir="${v2.out.root}" includes="com/companyname/server/applic/**/*.class"/>
* <fileset dir="${v2.out.root}" includes="com/companyname/common/utils/SeaDef*.class"/>
*/
lazy val jarPLCExample = project.in(file(".")).
settings(commonSettings: _*).
settings(
includeFilter in (Compile, unmanagedSources) :=
new SimpleFileFilter(file => filter3(file, "companyname", "server", "applic", List())) ||
new SimpleFileFilter(file => file.getName.startsWith("SeaDef"))
)

Having issues creating a report.xml file for QUnit + PhantomJS + Jenkins

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?
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:
cp /usr/local/CI/phantomjs-runner/runner.js /usr/local/CI/phantomjs-runner/runner-muted.js
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.
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

Build and deploy a Zend Framework PHP application in Jenkins

I'm setting up a jenkins job to build and deploy a Zend Framework 2 php application.
In my ant build script I've defined a lint job for validating php files.
The build job failed because lint detected an error in a ZF2 library file.
This is the output generated by lint:
[apply] PHP Fatal error: Constructor Zend\Captcha\Factory::factory() cannot be static in /var/lib/jenkins/workspace/XXX/vendor/zendframework/zendframework/library/Zend/Captcha/Factory.php on line 90
[apply] Errors parsing /var/lib/jenkins/workspace/XXX/vendor/zendframework/zendframework/library/Zend/Captcha/Factory.php
Does anybody know why the validation of Zend/Captcha/Factory.php fails ?
The ANT Task looks like this:
<target name="lint" description="Perform syntax check of sourcecode files">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/">
<include name="**/*.php" />
<modified />
</fileset>
<fileset dir="${basedir}/tests">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
Your problem is because Zend Framework requires php 5.3.3 or later. Since your Jenkins box uses 5.3.2, this give a variety of problems. One of them is apparently the error you have now.
I think you haven't noticed the error before because on the development system you have a 5.3.3+ install. Try to update your testing environment to a newer version of php, that will remove this particular problem.
Update
To clarify my answer a bit, there is one backwards compatibility break in php 5.3.3 which comes back in your environment. Check this changelog and particularly this statement:
Backwards incompatible change:
Methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn't affect non-namespaced classes.
<?php
namespace Foo;
class Bar {
public function Bar() {
// treated as constructor in PHP 5.3.0-5.3.2
// treated as regular method in PHP 5.3.3
}
}
?>
There is no impact on migration from 5.2.x because namespaces were only introduced in PHP 5.3.
In the case of Zend\Captcha\Factory, there is a method factory() which is static so you can call Zend\Captcha\Factory::factory(). On php 4 and 5 up to 5.3.2, this method is also parsed as the constructor for the factory. And constructors cannot be static.
A linter will give you a fatal error for this case.

Passing a variable into ant

If I pass a variable to ant by doing
ant -Dsomething=blah
How can I refer to it in my build.xml? I tried #something# and ${something} but neither seem to work.
Ultimately what I am trying to do is set some properties (versions) at compile time.
update: the problem of course turned out to be somewhere else - accepting the most complete looking answer with examples
Don't you hate it when you over think these things:
<project name="test">
<echo message="The value of foo is ${foo}"/>
</project>
Now, I'll run my program. Notice that I never defined a value for property foo in my build.xml. Instead, I'll get it from the command line:
$ ant -Dfoo=BAR_BAR_FOO
test:
[echo] The value of foo is BAR_BAR_FOO
BUILD SUCCESSFUL
time: 0 seconds
See. Nothing special at all. You treat properties set on the command line just like normal properties.
Here's where the fun comes in. Notice that I've defined the property foo in my build.xml this time around:
<project name="test">
<property name="foo" value="barfu"/>
<echo message="The value of foo is ${foo}"/>
</project>
Now watch the fun:
$ ant
test:
[echo] The value of foo is barfu
BUILD SUCCESSFUL
time: 0 seconds
Now, we'll set the property foo on the command line:
$ ant -Dfoo=BAR_BAR_FOO
test:
[echo] The value of foo is BAR_BAR_FOO
BUILD SUCCESSFUL
time: 0 seconds
See the command line overrides the value I set in the build.xml file itself. This way, you can have defaults that can be overwritten by the command line parameters.
It sounds like you want to do something like the following:
<mkdir dir="build/src"/>
<copy todir="build/src" overwrite="true">
<fileset dir="src" includes="**/*.java"/>
<filterset>
<filter token="VERSION" value="${version}"/>
</filterset>
</copy>
...which will cause your source to get copied, replacing #VERSION#:
public class a { public static final String VERSION = "#VERSION#"; }
...and then include build/src in your javac src.
That said, I don't recommend this approach since the source copy step is expensive, and it will undoubtedly cause confusion. In the past, I've stored a version.properties file in my package with version=x.y. In my Java code, I used Class.getResourceAsStream("version.properties") and java.util.Properties. In my build.xml, I used <property file="my/pkg/version.properties"/> so that I could create an output-${version}.jar.
${argsOne} works for me and is easily referenced if the invoking command is
ant -DargsOne=cmd_line_argument
Ant documentation also says so. This should work, try running with ant -debug and paste the output.

What's the use of Ant's extension-point if/unless attributes?

When you define an extension-point in an Ant build file you can have it conditional by using the if or unless attribute. On a target the if/unless prevent it's tasks from being run. But an extension-point doesn't have any tasks to conditionally run, so what does the condition do? My thought (which proved to be incorrect in Ant 1.8.0) is it would prevent any tasks that extend the extension-point from being run. Here is an example build script showing the problem:
<project name = "ext-test"
default = "main">
<property name = "do.it" value = "false" />
<extension-point name = "init"/>
<extension-point name = "doit" depends = "init" if = "${do.it}" />
<target name = "extend-init" extensionOf = "init">
<echo message = "Doing extend-init." />
</target>
<target name = "extend-doit" extensionOf = "doit">
<echo message = "Do It! (${do.it})" />
</target>
<target name = "main" depends = "doit">
<echo message = "Doing main." />
</target>
</project>
Using the command:
ant -v
Relults in:
Apache Ant version 1.8.0 compiled on February 1 2010
Trying the default build file: build.xml
Buildfile: /Users/bob/build.xml
Detected Java version: 1.6 in: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Detected OS: Mac OS X
parsing buildfile /Users/bob/build.xml with URI = file:/Users/bob/build.xml
Project base dir set to: /Users/bob
parsing buildfile jar:file:/Users/bob/Documents/Development/3P-Tools/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/Users/bob/Documents/Development/3P-Tools/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `main' is [extend-init, init, extend-doit, doit, main]
Complete build sequence is [extend-init, init, extend-doit, doit, main, ]
extend-init:
[echo] Doing extend-init.
init:
extend-doit:
[echo] Do It! (false)
doit:
Skipped because property 'false' not set.
main:
[echo] Doing main.
BUILD SUCCESSFUL
Total time: 0 seconds
You will notice the target extend-doit is executed but the extention-point itself is skipped. Since an extention-point doesn't have any tasks exactly what has been skipped? Any targets that depend on the extention-point still get executed since a skipped target is a successful target. What is the value of the if/unless attributes on an extention-point?
I'm guessing there is no actual use for them, they probably appear as attributes because extension-point extends target (the associated java classes do).

Resources