Blank JUnit reports generated through ANT - ant

<property name="wspace.home" value="${basedir}"/>
<property name="wspace.jars" value="D:\\softwares\\jars"/>
<property name="test.dest" value="${wspace.home}/build"/>
<property name="test.src" value="${wspace.home}/src"/>
<property name="test.reportsDir" value="D:\reports"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${wspace.jars}">
<include name="*.jar"/>
</fileset>
</path>
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${wspace.jars}" includes="*.jar"/>
</path>
<pathconvert pathsep="."
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath-----: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${wspace.jars}" includes="*.jars"/>
</path>
<!-- run -->
<target name="run">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}" includes="**/*"/>
</delete>
<java jar="${wspace.jars}" fork="true" spawn="true"/>
<junit fork="yes" haltonfailure="no" printsummary="yes">
<classpath refid="testcase.path"/>
<!-- <classpath ="&{test.classpath}"/> -->
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<include name="TestSuite.class"/>
</fileset>
</batchtest>
<formatter type="xml"/>
<classpath refid="testcase.path"/>
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TEST-.xml" />
</fileset>
<report todir="${test.reportsDir}"/>
</junitreport>
</target>
</project>
..........................................................................................
Reoprts are generated but they are blank, tried different solution mentioned is previou questions, but still not able to get.

I think testcase are not executed, do I have enetered something wrong in build.xml
Check below command prompt log
C:\Users\Vaibhav\Eclipse_Workspace\WebDriverTests>ant run
Buildfile: C:\Users\Vaibhav\Eclipse_Workspace\WebDriverTests
\build.xml
run:
[junitreport] Processing D:\reports\TESTS-TestSuites.xml to C:\Users\Vaibhav\AppData\Local\Temp\null526641997
[junitreport] Loading stylesheet jar:file:/C:/apache-ant-1.9.4/lib/ant-junit.jar
!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 524ms
[junitreport] Deleting: C:\Users\Vaibhav\AppData\Local\Temp\null526641997
BUILD SUCCESSFUL
Total time: 1 second

Related

Use JUnit with Jenkins & Ant Project

I am running Junit Tests on Jenkins via ant.
I can received the build success message in Jenkins, but JUnit result is error.
java.lang.ClassNotFoundException: JUnitTest
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
This is my build.xml.
<?xml version="1.0"?>
<project name="testProject" default="main" basedir=".">
<target name="init">
<property name="src" location="src" />
<property name="bin" location="bin" />
<property name="lib" location="WebContent/WEB-INF/lib" />
<property name="war.name" location="testProject.war" />
<property name="web" location="WebContent" />
<mkdir dir="${bin}" />
<tstamp>
<format property="DSTAMP" pattern="yyyyHHdd" />
<format property="TSTAMP" pattern="HHmm" />
</tstamp>
</target>
<target name="compile" depends="init">
<fileset dir="WebContent/WEB-INF/lib" includes="*.jar" />
</path>
<javac srcdir="src/test" destdir="${bin}" debug="on" includeantruntime="false">
<classpath refid="junit.jar"/>
<include name="*.java"/>
</javac>
<javac srcdir="src/testProject" destdir="${bin}" debug="on" includeantruntime="false">
<include name="*.java"/>
</javac>
</target>
<target name="junit4" depends="compile">
<delete dir="report" />
<mkdir dir="report" />
<junit printsummary="on" fork="false" haltonfailure="false">
<classpath refid="junit.jar"/>
<formatter type="xml"/>
<batchtest todir="report">
<fileset dir="src/test" includes="**/JUnit*.java" />
</batchtest>
</junit>
<junitreport todir="report">
<fileset dir="report" includes="TEST-*.xml" />
<report format="frames" todir="report"/>
</junitreport>
</target>
<target name="main" depends="clean,war">
<java classpath="${bin}" classname="testProject.HelloWorld">
</java>
</target>
<target name="war" depends="compile,junit4">
<war destfile="${bin}/${DSTAMP}.war" webxml="${web}/WEB-INF/web.xml">
<fileset dir="${web}">
<include name="**/*.*" />
<exclude name="WEB-INF/web.xml" />
</fileset>
</war>
</target>
<target name="clean">
<delete dir="${bin}" />
</target>
</project>
I've reviewed other similar issues, but it didn't work.
Why can't it find the Class?

build.xml:43 compile failed see compiler error output for details

I am trying to compile and build the source files into a jar file using ant from the command line. (windows 7)
However I am getting the following error:
....\build.xml:43: Compile failed see the copiler error output for details
My build file is given below:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="jar.client">
<!--Auto generated ant build file-->
<property environment="env"/>
<property name="axis2.home" value="${env.AXIS2_HOME}"/>
<property name="project.base.dir" value="."/>
<property name="maven.class.path" value=""/>
<property name="name" value="addtaxihire_14cabs"/>
<property name="src" value="${project.base.dir}/src"/>
<property name="test" value="${project.base.dir}/test"/>
<property name="build" value="${project.base.dir}/build"/>
<property name="classes" value="${build}/classes"/>
<property name="lib" value="${build}/lib"/>
<property name="resources" value="${project.base.dir}/resources"/>
<property value="" name="jars.ok"/>
<path id="axis2.class.path">
<pathelement path="${java.class.path}"/>
<pathelement path="${maven.class.path}"/>
<fileset dir="${axis2.home}">
<include name="lib/*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${lib}"/>
</target>
<target depends="init" name="pre.compile.test">
<!--Test the classpath for the availability of necesary classes-->
<available classpathref="axis2.class.path" property="stax.available" classname="javax.xml.stream.XMLStreamReader"/>
<available classpathref="axis2.class.path" property="axis2.available" classname="org.apache.axis2.engine.AxisEngine"/>
<condition property="jars.ok">
<and>
<isset property="stax.available"/>
<isset property="axis2.available"/>
</and>
</condition>
<!--Print out the availabilities-->
<echo message="Stax Availability= ${stax.available}"/>
<echo message="Axis2 Availability= ${axis2.available}"/>
</target>
<target depends="pre.compile.test" name="compile.src" if="jars.ok">
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
<classpath refid="axis2.class.path"/>
</javac>
</target>
<target depends="compile.src" name="compile.test" if="jars.ok">
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}">
<src path="${test}"/>
<classpath refid="axis2.class.path"/>
</javac>
</target>
<target depends="pre.compile.test" name="echo.classpath.problem" unless="jars.ok">
<echo message="The class path is not set right! Please make sure the following classes are in the classpath 1. XmlBeans 2. Stax 3. Axis2 "/>
</target>
<target depends="jar.server, jar.client" name="jar.all"/>
<target depends="compile.src,echo.classpath.problem" name="jar.server" if="jars.ok">
<copy toDir="${classes}/META-INF" failonerror="false">
<fileset dir="${resources}">
<include name="*.xml"/>
<include name="*.wsdl"/>
<include name="*.xsd"/>
</fileset>
</copy>
<jar destfile="${lib}/${name}.aar">
<fileset excludes="**/Test.class" dir="${classes}"/>
</jar>
</target>
<target if="jars.ok" name="jar.client" depends="compile.src">
<jar destfile="${lib}/${name}-test-client.jar">
<fileset dir="${classes}">
<exclude name="**/META-INF/*.*"/>
<exclude name="**/lib/*.*"/>
<exclude name="**/*MessageReceiver.class"/>
<exclude name="**/*Skeleton.class"/>
</fileset>
</jar>
</target>
<target if="jars.ok" depends="jar.server" name="make.repo">
<mkdir dir="${build}/repo/"/>
<mkdir dir="${build}/repo/services"/>
<copy file="${build}/lib/${name}.aar" toDir="${build}/repo/services/"/>
</target>
<target if="jars.ok" depends="make.repo" name="start.server">
<java fork="true" classname="org.apache.axis2.transport.http.SimpleHTTPServer">
<arg value="${build}/repo"/>
<classpath refid="axis2.class.path"/>
</java>
</target>
<target if="jars.ok" depends="compile.test" name="run.test">
<path id="test.class.path">
<pathelement location="${lib}/${name}-test-client.jar"/>
<path refid="axis2.class.path"/>
<pathelement location="${classes}"/>
</path>
<mkdir dir="${build}/test-reports/"/>
<junit haltonfailure="yes" printsummary="yes">
<classpath refid="test.class.path"/>
<formatter type="plain"/>
<batchtest fork="yes" toDir="${build}/test-reports/">
<fileset dir="${test}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
</project>
and probably the 43rd-45th lines of the build file are:
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
<classpath refid="axis2.class.path"/>
</javac>
Thanks in advance for any solution/suggestion.
The problem is not in the build.xml. It's in your java code. This implies the message:
Compile failed see the compiler error output for details

Execute selenium test suit jar using ant

I have a Selenium RC testing project that uses JUNIT test cases. I have made a JAR file of it and I am executing that JAR through ANT build file:
My ant file looks like this:
*
<project name="test" default="run-all" basedir=".">
<property name="src" value="./src" />
<property name="lib" value="./lib" />
<property name="bin" value="./bin" />
<property name="report" value="./report" />
<path id="test.classpath">
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="init">
<delete dir="${bin}" />
<mkdir dir="${bin}" />
</target>
<target name="exec" depends="init">
<delete dir="${report}" />
<mkdir dir="${report}" />
<mkdir dir="${report}/xml" />
<junit printsummary="yes" haltonfailure="no">
<batchtest fork="yes" todir="${report}/xml">
<resources>
<zipfileset src="BVTTest.jar" includes="**/*TestSuite.class"/>
</resources>
</batchtest>
<classpath>
<fileset dir="">
<include name="**/*.jar" />
</fileset>
</classpath>
</junit>
<junitreport todir="${report}">
<fileset dir="${report}/xml">
<include name="TEST*.xml" />
</fileset>
<report format="frames" todir="C:/eclipse/html" />
</junitreport>
</target>
<target name="start-selenium-server">
<java jar="selenium-server-standalone-2.25.0.jar" fork="true" spawn="true">
<arg line="-timeout 30" />
</java>
</target>
<target name="browse">
<exec executable="C:\Program Files\Internet Explorer\iexplore.exe">
<arg value="C:/eclipse/html/index.html"/>
</exec>
</target>
<target name="stop-selenium-server">
<get taskname="selenium-shutdown"
src="http://localhost:4444/selenium-server/driver/?cmd=shutDown"
dest="result.txt"
ignoreerrors="true" />
<echo message="selenium server stopped succesfully"/>
</target>
<target name="run-all">
<parallel>
<antcall target="start-selenium-server">
</antcall>
<sequential>
<echo taskname="waitfor" message="Wait for proxy server launch" />
<waitfor maxwait="1" maxwaitunit="minute" checkevery="100">
<http url="http://localhost:4444/selenium-server/
driver/?cmd=testComplete" />
</waitfor>
<antcall target="exec">
</antcall>
<antcall target="stop-selenium-server">
</antcall>
<antcall target="browse">
</antcall>
</sequential>
</parallel>
</target>
</project>
*
What it does is, it skips the <junit>; and after <mkdir> jumps directly to <junitreport>.
Please help.

HTML Report for JUNIT by ANT

How can I generate HTML reports from JUnit using Ant when there are test failures?
The reports are generated when there are no failures.
Also, how can we define our own XSLT for the report generation?
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant Example" default="all" basedir=".">
<property name="project_name" value="junitSamples" />
<property name="src" location="src" />
<property name="build" location="build/classes" />
<property name="lib" location="lib" />
<property name="reports" location="reports" />
<target name="init" depends="clean">
<mkdir dir="${build}" />
<mkdir dir="${lib}" />
<mkdir dir="${reports}" />
<mkdir dir="${reports}/raw/" />
<mkdir dir="${reports}/html/" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" description="compile the source code ">
<classpath>
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="clean">
<delete dir="build" />
<delete dir="${reports}" />
</target>
<target name="run-tests" depends="compile">
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
<classpath>
<pathelement path="${build}" />
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml" />
<fileset dir="${src}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${reports}\html\" />
</junitreport>
</target>
<target name="all" depends="clean, test" />
</project>
To specify your own stylesheets, use the "styledir" attribute:
<report styledir="${resources}/junit" format="..." todir="..." />
As noted, you must use the "junit-noframes.xsl" stylesheet name.
JUnit report docs.
You set haltonfailure="yes" it means that if one test fails build operation will stop.
This is from the ant documentation:
"Stop the build process if a test fails (errors are considered failures as well)."
Read more here- https://ant.apache.org/manual/Tasks/junit.html

Ant is not recognizing Log4j.properties file

I have been struck in this issue for past two days.Please help me in this. I am running my JUNIT scripts by using ANT. Reports are being generated, but ANT is not able to locate my log4j.properites file. When I am running through eclipse, logs are being generated. My problem here is I want logs when I am running through ANT.DO I need to set any properties.
What is the mistake I am doing?
Please help me.
My Log:
#Application Logs
#log4j.logger.devpinoyLogger
log4j.rootLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=/Users/Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false
build.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="Module_Junit_Ant" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${ws.home}/jars"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${ws.home}/reports"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${ws.jars}">
<include name="*.jar"/>
</fileset>
</path>
<!--target name="start-selenium-server">
<java jar="${ws.home}/lib/selenium-server.jar"/>
</target-->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
<fileset dir="${test.src}" includes="*.properties"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<target name="run" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}" includes="**/*"/>
</delete>
<java jar="${ws.jars}" fork="true" spawn="true" />
<junit fork="yes" haltonfailure="no" printsummary="yes">
<classpath refid="testcase.path" />
<!-- <classpath ="${test.classpath}"/> -->
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<include name="LogTest.class" />
<!--include name="tests/suite1/FirstSuiteRunner.class" />
<include name="tests/suite1/FirstSuiteRunner.class" /-->
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="testcase.path" />
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reportsDir}" />
</junitreport>
</target>
<target name="email" >
<java classname="util.SendMail" classpath="${test.dest}" classpathref="testcase.path" />
</target>
</project>
Where are your log4j.properties located ?
What works for me it to put a
< pathelement location="x/y/z"/>
inside the
< path id="testcase.path">
which points to a folder which contains a log4j.properties!
So in this example your log4j.properties should be inside the 'z' folder!

Resources