Ant Junit & Selenium no information in reports - eclipse

I am running so juit tests in eclipse usin Ant and Selenium Webdriver.
The tests run as expected and I see the result in the console and the eb report is generated but the results are not included.
Below is my build.xml file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<property environment="env"/>
<property name="ECLIPSE_HOME" value="F:/Program Files (x86)/eclipse/"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<property name="junit.output.dir" value="C:/Users/kev/workspace_hlgliveTest/hlglive/junit/"/>
<path id="hlglive.classpath">
<pathelement location="bin"/>
<pathelement location="C:/Selenium/selenium-server-standalone-2.44.0.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="hlglive.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="classHlglive">
<java classname="hlglive.classHlglive" failonerror="true" fork="yes">
<classpath refid="hlglive.classpath"/>
</java>
</target>
<target name="hmliveCH">
<java classname="hlglive.hmliveCH" failonerror="true" fork="yes">
<classpath refid="hlglive.classpath"/>
</java>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
</project>
And here is the console output
Buildfile: C:\Users\kev\workspace_hlgliveTest\hlglive\build.xml
build-subprojects:
init:
build-project:
[echo] hlglive: C:\Users\kev\workspace_hlgliveTest\hlglive\build.xml
build:
hmliveCH:
[java] Starting ChromeDriver (v2.11.298604 (75ea2fdb5c87f133a8e1b8da16f6091fb7d5321e)) on port 24805
[java] Only local connections are allowed.
[java] Starting Chrome login Test
[java] Current page title is: Haulage Manager Live
[java] Testing combination of user name: and password:
[java] Current page title is: Haulage Manager Live
[java] Testing combination of user name: KEV and password:
[java] Current page title is: Haulage Manager Live
[java] Testing combination of user name: KEV and password: bollo
[java] Current page title is: Haulage Manager Live
[java] Testing combination of user name: KEVIN and password: bollox
[java] Current page title is: Haulage Manager Live
[java] Testing combination of user name: KEV and password: bollox
[java] Current page title is: Haulage Manager Live
[java] Current page title is: Haulage Manager Live
[java] Chrome Test complete
junitreport:
[junitreport] Processing C:\Users\kev\workspace_hlgliveTest\hlglive\junit\TESTS-TestSuites.xml to C:\Users\kev\AppData\Local\Temp\null978404570
[junitreport] Loading stylesheet jar:file:/F:/Program%20Files%20(x86)/eclipse/plugins/org.apache.ant_1.9.2.v201404171502/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 565ms
[junitreport] Deleting: C:\Users\kev\AppData\Local\Temp\null978404570
BUILD SUCCESSFUL
Total time: 18 seconds
So all seems to run ok but when I look at the generated html pages all I see is this.
Can anyone point me to where I am going wrong please.
Thanks
Kev

<junitreport> combines the results of tests run using the <junit> task. You used to run a standalone program rather than using <junit> to run a test suite. Therefore, <junitreport> didn't see any tests run and correctly reported that zero tests were run.

Related

Ant build.xml working Eclipse. Not working direct

My buildfile seems to be running correctly (and generating junit test reports) correctly when executing in Eclipse, however when I execute directly with: ant -buildfile C:\....\build.xml the files aren't produced - and the cmd output suggests it's not running the tests.
I have two eclipse projects. JUnitTest1 which is the code. JUnitTestUnitTests which contains the test code.
I've followed the instructions here to create my buildfile in eclipse (selecting only the test project) and can see the files drop into the junit directory.
When I run ant command directly, no files are generated and it doesn't look like it's running my tests.
Why aren't the changes made via the eclipse GUI reflected in the build.xml? I thought it was auto updated?
Here's the eclipse config
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. --><project basedir="." default="build" name="JUnitTest1UnitTests">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../../tools/eclipse-mars/"/>
<property name="junit.output.dir" value="junit"/>
<property name="JUnitTest1.location" value="../JUnitTest1"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="JUnitTest1.classpath">
<pathelement location="${JUnitTest1.location}/bin"/>
<pathelement location="${JUnitTest1.location}/../../../../../tools/libs/hamcrest-core-1.3.jar"/>
<pathelement location="${JUnitTest1.location}/../../../../../tools/libs/junit-4.12.jar"/>
</path>
<path id="JUnitTest1UnitTests.classpath">
<pathelement location="bin"/>
<pathelement location="../../../../../tools/libs/hamcrest-core-1.3.jar"/>
<pathelement location="../../../../../tools/libs/junit-4.12.jar"/>
<path refid="JUnitTest1.classpath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall">
<ant antfile="build.xml" dir="${JUnitTest1.location}" inheritAll="false" target="clean"/>
</target>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects">
<ant antfile="build.xml" dir="${JUnitTest1.location}" inheritAll="false" target="build-project">
<propertyset>
<propertyref name="build.compiler"/>
</propertyset>
</ant>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="JUnitTest1UnitTests.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="JUnitTest1UnitTests">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="com.me.tests.MyTestClass" todir="${junit.output.dir}"/>
<classpath refid="JUnitTest1UnitTests.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
I believe I've fixed this.
Eclipse creates your build file and seperately, you configure your run configurations. These run configurations (where you specify the run order of the ant tasks) are not persisted or represented in the actual build file.
The default target of the build file is the target="build" ... So you need to manually edit the build file and use the depends="..." clause to chain together the dependancies of your tasks.
This page (read example build file and see final line) has a great explanation of the depends clause.

Ant and Tomcat7: java.net.ConnectException

I'm following along with this Springsource.org tutorial except I'm using Tomcat7 instead, and I'm encountering the following error whenever I run "ant list" or "ant reload" or "ant start".
/home/patchouli/workspace/springapp/build.xml:110: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at sun.net.NetworkClient.doConnect(NetworkClient.java:178)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:240)
at sun.net.www.http.HttpClient.New(HttpClient.java:321)
at sun.net.www.http.HttpClient.New(HttpClient.java:338)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:935)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:876)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:801)
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:210)
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:150)
at org.apache.catalina.ant.StartTask.execute(StartTask.java:44)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Here is my build.xml file:
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="springapp"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${appserver.lib}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message="install --> Install application in Tomcat"/>
<echo message="reload --> Reload application in Tomcat"/>
<echo message="start --> Start Tomcat application"/>
<echo message="stop --> Stop Tomcat application"/>
<echo message="list --> List Tomcat applications"/>
<echo message=""/>
</target>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.6" target="1.6" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build" description="Deploy application">
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${name}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<path id="catalina-ant-classpath">
<fileset dir="${appserver.lib}">
<include name="catalina-ant.jar"/>
<include name="tomcat-coyote.jar"/>
<include name="tomcat-util.jar"/>
</fileset>
<fileset dir="${appserver.home}/bin">
<include name="tomcat-juli.jar"/>
</fileset>
</path>
<taskdef name="list"
classname="org.apache.catalina.ant.ListTask"
classpathref="catalina-ant-classpath"/>
<taskdef name="reload"
classname="org.apache.catalina.ant.ReloadTask"
classpathref="catalina-ant-classpath"/>
<taskdef name="start"
classname="org.apache.catalina.ant.StartTask"
classpathref="catalina-ant-classpath"/>
<taskdef name="stop"
classname="org.apache.catalina.ant.StopTask"
classpathref="catalina-ant-classpath"/>
<target name="reload">
<reload url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${name}"/>
</target>
<target name = "start">
<start url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"/>
</target>
<target name = "stop">
<stop url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"
failonerror="false"/>
</target>
<target name="list">
<list url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"/>
</target>
<target name="install">
<install url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${name}"
war="${name}"/>
</target>
And my build.properties file:
# Ant properties for building the springapp
appserver.home=/usr/share/tomcat7
appserver.lib=${appserver.home}/lib
deploy.path=/var/lib/tomcat7/webapps
tomcat.manager.url=http://localhost:8080/manager/html
tomcat.username=admin
tomcat.password=admin
I am pretty frustrated. At the moment, I can just start tomcat7 manually and go to localhost:8080/springapp/index.jsp without any issue. But I want this to be automated using Apache Ant. It seems like the problem is that Ant cannot connect to Tomcat. Any thoughts?
You seem to have similar problem I faced with Tomcat 7 and posted at ant target to deploy war to tomcat7/webapps.
Two Changes you need apply :
1) update tomcat manager url for Tomcat 7 (in build.properties)
# Ant properties for building the springapp
tomcat.manager.url=http://localhost:8080/manager/text
2) add extra manager role to user (in TOMCAT_DIRECTORY/conf/tomcat-users.xml)
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="tomcat,manager-gui,manager-script"/>
MAKE SURE YOUR TOMCAT IS ALREADY RUNNING, BEFORE ant TRIES TO DEPLOY WAR.
Do you have spaces or tabs after any of these lines in your build.properties?
tomcat.manager.url=http://localhost:8080/manager/html
tomcat.username=admin
tomcat.password=admin
They would be treated literally.
I had the same problem. If you are on windows maybe the paths cause this, because the tutorial is based on a linux OS. You can try backslasses (\) instead of (/)
appserver.home=\usr\share\tomcat7
appserver.lib=${appserver.home}\lib
deploy.path=\var\lib\tomcat7\webapps
To solve this I also replaced the variables with the absolute paths of tomcat's installation folder.
Start the tomcat manually where it is installed.
Path of bat/sh : {tomcat--ver-}/bin/startup.
And then run the build.xml

Eclipse with Java EE (EJB), ANT and Jenkins / Hudson

My Goal is to get a Enterprise Java Application to be built on Jenkins. The Application consists of 4 Projects (Client-Interfaces, Webapplcation (incl. Faces), EJB Application (incl. JPA), EAR-Container-Project).
When Eclipse deploys this projects to a glassfish server, it assembles the Webapplication (war-file), the Client-Interfaces (jar-file) and the EJB-Interfaces (jar-file) into one ear-File.
Now, if I want to use continous integration I need to achieve the same on the CI-Server jenkins.
My first idea was to solve this with ant, so I used the Export-Function of Eclipse and generated build-Files for the projects.
The Problem is that the generated Build-Files refer to the Java EE Libraries (such as Glassfish-Runtime, JPA-Library, etc) which are outside of the project directory. There are about 30 libraries.
This implies that I cannot use the file on jenkins, because this libraries are missing. Of course I can copy these, but I don't think this is how it should be done.
So, what is the best way to get the Java EE Enterprise Application to be built on the CI Server? Do I have to write the ANT-Script all by myself and copy the libraries into the project? Or am I Missing something obvious?
Since I did not found anything that suited for me, I wrote an ant script that covered my needs on my own.
Here is my solution if this helps anyone in the future:
`
<project basedir="." default="build" name="Project">
<available property="glassfishdir" value="/opt/glassfish3/glassfish/modules"
file="/opt/glassfish3/glassfish/modules" type="dir" />
<!-- ########### Property Declarations ################################################################################################################### -->
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="builddir" value="build" />
<property name="outputartifacts" value="out" />
<property name="web.name" value="ProjectWeb" />
<property name="web.projectpath" value="ProjectWeb"/>
<property name="web.src" value="${web.projectpath}/src" />
<property name="web.builddir" value="${builddir}/web" />
<property name="web.builddir.classes" value="${web.builddir}/WEB-INF/classes"/>
<property name="ejb.name" value="ProjectEJB" />
<property name="ejb.projectpath" value="ProjectEJB"/>
<property name="ejb.src" value="${ejb.projectpath}/src"/>
<property name="ejb.builddir" value="${builddir}/ejb" />
<property name="ejb.builddir.classes" value="${ejb.builddir}/classes" />
<property name="ejbclient.name" value="ProjectEJBClient" />
<property name="ejbclient.projectpath" value="ProjectEJBClient"/>
<property name="ejbclient.src" value="${ejbclient.projectpath}/src"/>
<property name="ejbclient.builddir" value="${builddir}/ejbclient" />
<property name="ejbclient.builddir.classes" value="${ejbclient.builddir}/classes"/>
<property name="ear.name" value="ProjectApplication" />
<property name="ear.dir" value="ProjectEAR" />
<!-- ########### Main Targets ################################################################################################################### -->
<target name="build" depends="create-ear">
</target>
<target name="clean-build">
<antcall target="clean" />
<antcall target="build" />
</target>
<target name="clean">
<delete dir="${builddir}"/>
<delete dir="${outputartifacts}"/>
</target>
<target name="init">
<mkdir dir="${outputartifacts}" />
</target>
<!-- ########### EJB App ################################################################################################################### -->
<target name="init-ejb" depends="init">
<mkdir dir="${ejb.builddir}" />
<copy includeemptydirs="false" todir="${ejb.builddir.classes}">
<fileset dir="${ejb.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="build-ejb" depends="init-ejb">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejb.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejb.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${outputartifacts}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ########### WEB ################################################################################################################### -->
<target name="init-web" depends="init">
<mkdir dir="${web.builddir.classes}"/>
<copy includeemptydirs="false" todir="${web.builddir}">
<fileset dir="${web.projectpath}/WebContent">
</fileset>
</copy>
<copy includeemptydirs="false" todir="${web.builddir.classes}">
<fileset dir="${web.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-web,create-ejb-client" name="build-web">
<javac debug="true" debuglevel="${debuglevel}" destdir="${web.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${web.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="out/">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############## EJB CLIENT ################################################################################################################ -->
<target name="init-ejb-client" depends="init">
<mkdir dir="${ejbclient.builddir}"/>
<copy includeemptydirs="false" todir="${ejbclient.builddir.classes}">
<fileset dir="${ejbclient.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-ejb-client" name="build-ejb-client">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejbclient.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejbclient.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############ CREATE ARCHIVES################################################################################################################## -->
<target name="create-web" depends="build-web">
<war destfile="${outputartifacts}/${web.name}.war" basedir="${web.builddir}" webxml="${web.projectpath}/WebContent/WEB-INF/web.xml"/>
</target>
<target name="create-ejb-client" depends="build-ejb-client">
<jar destfile="${outputartifacts}/${ejbclient.name}.jar" basedir="${ejbclient.builddir.classes}" includes="**/*"/>
</target>
<target name="create-ejb" depends="build-ejb">
<jar destfile="${outputartifacts}/${ejb.name}.jar" basedir="${ejb.builddir.classes}" includes="**/*">
<manifest>
<attribute name="Class-Path" value="${ejbclient.name}.jar"/>
</manifest>
</jar>
</target>
<target name="create-ear" depends="create-ejb-client,create-web,create-ejb">
<ear destfile="${outputartifacts}/${ear.name}.ear" appxml="${ear.dir}/EarContent/META-INF/application.xml">
<fileset dir="${outputartifacts}" includes="*.jar,*.war"/>
</ear>
</target>
</project>
`
Use Maven.
Maven allow to define all dependencies in a single xml file (pom), dependencies which will be automatically downloaded from internet at compilation phase.
Maven come with a set of plugin to facilitate continuous integration like being able to start a container, run the test and close it automatically.
Maven integrate natively with jenkins.
Maven defines a complex lifecycle designed for this kind of problematic and allowing to compile, run unit test, package, run integration test and deploy with a single command triggered from jenkins;
Maven is definitively THE solution here.
You can also auto-create the build.xml in Eclipse using "Export... > General\Ant Buildfile" from the project context menu. This way the correct classpath is generated to your JAR's already available in the project.
Chances are that if there are dependencies between the projects, you only need to configure one build file to be run on Jenkins, as it will automatically call the build files from the other projects.

how to use the jcoverage java tool by using ANT in eclipse

I wanna prepare jcoverage report for my unit tests by using ANT and eclipse. I'm using
Apache Ant(TM) version 1.8.3 compiled on February 26 2012
selenium-server-standalone-2.20.0
junit-4.8.1.jar
eclipse sdk 3.6.1
i tried as mentioned in this link here.
but i'm not able to succeed.please provide if any documents are available or make me clear how to prepare report.
my ant file:
<?xml version="1.0"?>
<!DOCTYPE project [
<!ENTITY start_stop_selenium SYSTEM "start_stop_selenium.xml">
<!ENTITY properties_build_clean_compile_report SYSTEM "properties_build_clean_compile_report.xml">
]>
<project name="Run Selenium Tests" default="all_selenium_tests" basedir=".">
<property name="libs" location="lib" />
<property name="build.dir" value="${basedir}/build/"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="build.test-classes.dir" value="${build.dir}/test-classes"/>
<property name="build.instrumented-classes.dir" value="${build.dir}/instrumented-classes"/>
<property name="build.coverage.dir" value="${build.dir}/coverage"/>
<property name="build.reports.dir" value="${build.dir}/reports"/>
<property name="lib.dir" value="lib"/>
<property name="src" value="src"/>
<property name="src.dir" value="${basedir}/src/java"/>
<property name="test.dir" value="${basedir}/src/test"/>
<!-- Corresponding Jar file for the Jcoverage.-->
<path id="jcoverage.path">
<fileset dir="${lib.dir}">
<include name="jcoverage-1.0.5.jar"/>
<include name="log4j-1.2.9.jar"/>
<include name="bcel-5.1.jar"/>
<include name="jakarta-oro-2.0.7.jar"/>
<include name="java-getopt-1.0.9.jar"/>
</fileset>
</path>
<path id="junit.class.path">
<fileset dir="${lib.dir}">
<include name="ant-junit.jar"/>
<include name="jcoverage-1.0.5.jar"/>
<include name="log4j-1.2.9.jar"/>
<include name="bcel-5.1.jar"/>
<include name="jakarta-oro-2.0.7.jar"/>
<include name="java-getopt-1.0.9.jar"/>
<include name="junit-4.8.1.jar"/>
<include name="selenium-server-standalone-2.20.0.jar"/>
<include name="jetty-repacked-7.6.1.jar"/>
<include name="org.mortbay.jetty-6.0.0alpha2.jar"/>
<include name="httpclient-4.1.2.jar"/>
<include name="httpcore-4.1.3.jar"/>
<include name="httpmime-4.1.2.jar"/>
<include name="selenium-java-2.20.0.jar"/>
<include name="selenium-java-2.20.0-srcs.jar"/>
<include name="logging-selenium-1.2.jar"/>
<include name="poi-3.7-20101029.jar"/>
<include name="robotframework-2.5.4.1.jar"/>
<include name="saxon-8.7.jar"/>
<include name="jxl.jar"/>
</fileset>
</path>
<target name="init">
<!-- <delete dir="${build.dir}"/>
<delete dir="${build.classes.dir}"/>
<delete dir="{build.test-classes.dir}"/>
<delete dir="${build.coverage.dir}"/>
<delete dir="${build.instrumented-classes.dir}"/>
<delete dir="${build.reports.dir}"/> -->
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.test-classes.dir}"/>
<mkdir dir="${build.coverage.dir}"/>
<mkdir dir="${build.instrumented-classes.dir}"/>
<mkdir dir="${build.reports.dir}"/>
</target>
<target name="compile" description="compile all classes">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" failonerror="yes" debug="yes">
</javac>
</target>
<target name="instrument" description="Add jcoverage instrumentation">
<instrument todir = "${build.instrumented-classes.dir}">
<ignore regex="org.apache.log4j.*"/>
<fileset dir="${build.classes.dir}">
<include name="**/*.class"/>
</fileset>
</instrument>
</target>
<target name="test" description="Unit test the application">
<javac srcdir="${test.dir}" destdir="${build.test-classes.dir}" failonerror="yes" debug="yes">
<classpath refid="junit.class.path"/>
<classpath location="${build.classes.dir}"/>
</javac>
<junit fork="yes" dir="${basedir}" errorProperty="test.failed" failureProperty="test.failed">
<!-- note the classpath order, instrumented classes are before the original (uninstrumented) classes. -->
<classpath refid="junit.class.path"/>
<classpath location="${build.instrumented-classes.dir}"/>
<classpath location="${build.classes.dir}"/>
<classpath location="${build.test-classes.dir}"/>
<!-- the instrumented classes reference classes used by the jcoverage runtime. -->
<classpath refid="jcoverage.path"/>
<formatter type="xml"/>
<batchtest todir="${build.reports.dir}" >
<fileset dir="${build.test-classes.dir}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
<taskdef classpathref="jcoverage.path" resource="tasks.properties"/>
<target name="coverage" description="HTML and XML coverage reports can be found in build/coverage">
<report srcdir="${src.dir}" destdir="${build.coverage.dir}"/>
<report srcdir="${src.dir}" destdir="${build.coverage.dir}" format="xml"/>
<echo> jcoverage reports have been generated. The HTML report is ${build.coverage.dir}/index.html The XML report is ${build.coverage.dir}/coverage.xml </echo>
</target>
<target name="all_selenium_tests" description="The Main Target for running all tests">
<antcall target="init"/>
<antcall target="compile"/>
<antcall target="instrument"/>
<antcall target="test"/>
<antcall target="coverage"/>
</target>
</project>
my junit class:
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
public class sample extends SeleneseTestCase {
static Selenium selenium;
#Before
public void setUp() throws Exception {
SeleniumServer seleniumserver=new SeleniumServer();
seleniumserver.boot();
seleniumserver.start();
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
selenium.start();
}
#Test
public void testjcoverage() throws Exception{
selenium.windowMaximize();
selenium.windowFocus();
selenium.setSpeed("1000");
selenium.open("/results-web/results/authentication/public/login?");
selenium.type("id=USER","labcorp" );
selenium.type("id=PASSWORD","Labcorp" );
selenium.click("css=input.loginButton");
selenium.stop();
}
}
console error:
Buildfile: E:\jcoverage\jcoverage\refactored-param-build.xml
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
all_selenium_tests:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
init:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
compiling:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
instrument:
BUILD FAILED
E:\jcoverage\jcoverage\refactored-param-build.xml:25: The following error occurred while executing this line:
E:\jcoverage\jcoverage\refactored-param-build.xml:96: Problem: failed to create task or type instrument
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Total time: 125 milliseconds
please provide a solution.
The error informs you that the javac compiler cannot find the junit jars. Although you specify the junit.class.path as the class path in the compiling ant target, that classpath contains references to the ${libs} property that is not defined anywhere in the build.xml
Also, you should move the property definitions (like lib.dir) before you use them (e.g. before the definition of jcoverage.path that references ${lib.dir})
Note: you can see the classpath used by either calling ant with the -verbose option or calling the <echo>${junit.class.path}</echo> task before the <javac> task

Ant TestNG build works in Eclipse but not from terminal

I'm able to run an Ant build from Eclipse by right clicking and selecting Ant Build.
When I attempt to execute the same build by running Ant from cmd I get results that the "Build Was Successful" but nothing is built.
Build.xml file
<property name ="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="name" value="value"/>
<target name="setClassPath">
<path id="classpath_jars">
<path id="${basedir}/"/>
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
<target name="loadTestNG" depends="setClassPath">
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<target name="init">
<mkdir dir="${build.dir}"/>
</target>
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean, init, setClassPath, loadTestNG">
<echo message="classpath: ${test.classpath}"/>
<echo message="compiling..."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}" encoding="cp1252"/>
</target>
<target name="run" depends="compile">
<testng classpath ="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
</testng>
</target>
</project>
And the Testng.xml
<suite name="Regression Test Suite">
<test name="My Test">
<classes>
<class name="com.RegressionTest.Sometest"/>
</classes>
</test>
</suite>
I determined the issue. I did not indicate the default target in my Project set up. Eclipse IDE was able to compile but in the terminal I was only using ANT and not indicating which target to build. So it was "building" successfully because I did not tell it what to build.