I am trying to test SOA through Ant Scripts in Jenkins. I am able to run the test of ant script in my PC but when I try to create the same in Jenkins job it fails.
The same command runs fine when I directly run in PC with Ant scripts.
Ant command for deploy works well but the ant test is giving me challenge.
Command below
ant -f ant-sca-test.xml -Dscatest.input=TestSOAAdd -Djndi.properties.input=D:/12c_Ant/ant_soa/jndi.properties
Below is the error message.
No changes for http://code.sunpowercorp.com/middleware-repo/fmw_12c/code/trunk/TestSOAAdd since the previous build
[ant_soa] $ cmd.exe /C "D:\Jdev1221\Middleware\Oracle_Home\oracle_common\modules\org.apache.ant_1.9.2\bin\ant.bat -file ant-sca-test.xml -DCompositeName=TestSOAAdd -DSVNCodePath=TestSOAAdd -Dtargetenv=proj ant-sca-test.xml -Dscatest.input=TestSOAAdd -Djndi.properties.input=D:\12c_Ant\ant_soa\jndi.properties && exit %%ERRORLEVEL%%"
Buildfile: D:\12c_Ant\ant_soa\ant-sca-test.xml
[echo] Running scatest using oracle.home = D:\Jdev1221\Middleware\Oracle_Home
BUILD FAILED
Target "ant-sca-test.xml" does not exist in the project "ant-scactest".
Ant Test file below:
<?xml version="1.0" encoding="iso-8859-1" ?>
<project name="ant-scactest" default="test">
<!-- must have these properties available
-->
<!-- oracle.home -->
<condition property="oracle.home" value="D:\Oracle\Middleware\Oracle_Home">
<not><isset property="oracle.home"/></not>
</condition>
<fail message="oracle.home is not available. Please provide this property.">
<condition>
<not>
<isset property="oracle.home"/>
</not>
</condition>
</fail>
<import file="ant-soa-common.xml"/>
<property environment="env"/>
<fail message="JAVA_HOME is not available. Please provide this property.">
<condition>
<and>
<not>
<isset property="env.JAVA_HOME"/>
</not>
<not>
<isset property="java.passed.home"/>
</not>
</and>
</condition>
</fail>
<condition property="java.passed.home" value="${env.JAVA_HOME}">
<isset property="env.JAVA_HOME"/>
</condition>
<condition property="scatest.format" value="native">
<not>
<isset property="scatest.format"/>
</not>
</condition>
<condition property="scatest.result" value="${java.io.tmpdir}/out">
<not>
<isset property="scatest.result"/>
</not>
</condition>
<condition property="scatest.timeout" value="300">
<not>
<isset property="scatest.timeout"/>
</not>
</condition>
<property name="scatest.partition" value="default"/>
<!-- if wl_home is not provided use the default -->
<condition property="wl_home" value="${mw.home}/wlserver">
<not>
<isset property="wl_home"/>
</not>
</condition>
<!-- jars needed to run scatest ant task -->
<path id="scatest.tasks.class.path">
<fileset dir="${mw.home}/soa/soa/modules/oracle.soa.fabric_11.1.1">
<include name="fabric-runtime.jar"/>
<include name="fabric-ext.jar"/> <include name="oracle-soa-client-api.jar"/>
</fileset>
<fileset dir="${oracle.soa.mgmt.home}/soa/modules/oracle.soa.mgmt_11.1.1">
<include name="soa-infra-mgmt.jar"/>
</fileset>
<fileset dir="${mw.home}/soa/soa/modules/oracle.soa.bpel_11.1.1">
<include name="orabpel.jar"/>
<include name="orabpel-common.jar"/>
</fileset>
<pathelement location="${wl_home}/server/lib/weblogic.jar" />
<pathelement location="${wl_home}/server/lib/wlclient.jar" />
<fileset dir="${common.components.home}/modules">
<include name="oracle.jps/jps-api.jar"/>
<include name="oracle.jps/jps-internal.jar"/>
<include name="oracle.jps/jps-common.jar"/>
<include name="oracle.jrf/jrf-api.jar"/>
</fileset>
<!-- was specific files -->
<pathelement location="${oracle.soa.mgmt.home}/soa/modules/oracle.soa.mgmt_11.1.1/soa-client-stubs-was.jar"/>
<pathelement location="${was.home}/runtimes/com.ibm.ws.ejb.thinclient_8.0.0.jar"/>
<pathelement location="${was.home}/runtimes/com.ibm.ws.orb_8.0.0.jar"/>
<pathelement location="${was.home}/plugins/com.ibm.ws.runtime.jar"/>
<pathelement location="${was.home}/runtimes/com.ibm.ws.admin.client_8.0.0.jar"/>
<!--
<pathelement location="${was.home}/runtimes/com.ibm.ws.webservices.thinclient_8.0.0.jar"/>
-->
<!-- end was specific files -->
</path>
<property name="scatest.tasks.class.path" refid="scatest.tasks.class.path"/>
<echo message="Running scatest using oracle.home = ${oracle.home} "></echo>
<taskdef name="scatest"
classname="oracle.integration.platform.testfwk.ant.ScaTestTask">
<classpath>
<pathelement path="${scatest.tasks.class.path}"/>
</classpath>
</taskdef>
<target name="test" description="Run a composite test">
<echo message="Classpth = ${scatest.tasks.class.path}"/>
<echo message="Running scatest using oracle.home = ${oracle.home} ${scatest.input}"></echo>
<echo message="Using context = build.properties"></echo>
<echo message="Using path = ${scatest.tasks.class.path}"></echo>
<input message="Please enter composite name to test:"
addproperty="scatest.input"/>
<input message="Please enter the path to the jndi properties:"
addproperty="jndi.properties.input"/>
<scatest compositedn="${scatest.partition}/${scatest.input}" timeout="${scatest.timeout}"
xsl="${scatest.format}" runname="antRun-TestFwk"
resultsdir="${scatest.result}"
context="${jndi.properties.input}">
<!-- provide , separated list of suite names, defaults to all suites
<suite name="${scatestsuite.input}"/>
-->
</scatest>
</target>
<target name="report" description="Generate junit report for a composite test" >
<echo message="Generate report to ${scatest.result}"/>
<junitreport todir="${scatest.result}/xml">
<fileset dir="${scatest.result}">
<include name="BPEL-*.xml" />
</fileset>
<report format="frames" todir="${scatest.result}/html" />
</junitreport>
</target>
</project>
What am I doing wrong here?
Edit: I have changed the command to 'test' instead of and-sca-test.xml and it worked
test -Dscatest.input=TestSOAAdd -Djndi.properties.input=D:/12c_Ant/ant_soa/jndi.properties
I am facing issue with invoking the junit to generate a report.
Whatever input I give for "Test report XMLs" it fails with no matches error.
Related
My Build.xml as beolw
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project []>
<project name="Learning TestNG" default="usage" basedir=".">
<!-- ========== Initialize Properties ============================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="E:\SELENIUM_DOWNLOADS\Selenium Jars"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="testng-report-dir" value="${test.src}/TestNGreport" />
<!--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"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${ws.jars}">
<include name="*.jar"/>
</fileset>
</path>
<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>
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
</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}"
classpath="${test.classpath}"
includeantruntime="false" >
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}: ${test.dest}"
suitename="SuiteName">
<xmlfileset dir="src/test/resources/" includes="TestNG.xml"/>
</testng>
</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="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="src/test
/resources/testng-results.xsl" out="${ws.home}/XSLT_Reports/output
/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports
/output/"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
</xslt>
</target>
</project>
TestNG.xml is as below
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteName">
<test name="Login Test" allow-return-values="true">
<classes>
<class name="com.qtpselenium.zoho.project.testcases.LoginTest" />
</classes>
</test>
<test name="Lead Test" allow-return-values="true">
<classes>
<class name="com.qtpselenium.zoho.project.testcases.LeadTest" />
</classes>
</test>
Error displayed below
run:
[testng] [TestNG] [ERROR]
[testng] Cannot instantiate class com.qtpselenium.zoho.project.testcases.Lead
Test
BUILD SUCCESSFUL
Total time: 3 seconds
what will be solution for this not getting route cause..please it will better as early as possible
I have added all the configuration details regarding code coverage using jmockit in build.xml but it doesn't generate any report.
This is my configuration code:
<target name="tests" depends="testscompile,mkdirtests_clean,mkdirtests">
<junit fork="yes" forkmode="once" haltonfailure="no" printsummary="yes" >
<jvmarg value="-javaagent:../JUnitlib/jmockit.jar"/>
<sysproperty key="jmockit-coverage-output" value="html"/>
<sysproperty key="jmockit-coverage-outputDir" value="${reports.dir}"/>
<sysproperty key="jmockit-coverage-srcDirs" value="${src}"/>
<sysproperty key="jmockit-coverage-metrics" value="all"/>
<classpath>
<pathelement location="${classes}" />
<pathelement location="../JUnitlib/jmockit.jar" />
<pathelement location="../JUnitlib/junit-4.12.jar" />
<pathelement location="../JUnitlib/hamcrest-core-1.3.jar" />
<fileset dir="../WebContent/WEB-INF/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${tomcat.root}">
<include name="lib/log4j-1.2.17.jar"/>
</fileset>
</classpath>
<batchtest todir="${docs.dir}">
<fileset dir="${classes}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
<formatter type="xml"/>
</junit>
<!-- Junit Report generation -->
<junitreport todir="${reports.dir}">
<fileset dir="${docs.dir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${reports.dir}" />
</junitreport>
<antcall target="report.zip"/>
</target>
Here in this configuration reports for junit test and code coverage need to be generated but only junit test reports are only generates. Where i am going wrong please tell me?
The JMockit code coverage tool is in its own jar, jmockit-coverage.jar, not in jmockit.jar (although this will probably change in the next release or so).
The build script should remove the jvmarg line, and add a new pathelement for that separate jar.
I'm working with ant for the first time, read lots of tutorials and examples, and still cant make this works. Every target works, but with test im getting
"Test TestMaze failed (crashed)."
I've tried to change lot of things (using lot of examples), still nothing. Can anyone tell me where is the problem please? Thanks a lot.
<?xml version="1.0"?>
<project name="Maze" default="default" basedir=".">
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dest-server" />
<property name="test.dir" location="test" />
<property name="test.report.dir" location="testreport" />
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${test.report.dir}" />
</target>
<path id="junit.class.path">
<pathelement location="lib/junit-4.10.jar" />
<pathelement location="${build.dir}" />
</path>
<target name="compile" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" />
<javac srcdir="${test.dir}" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>
<jar destfile="${dist.dir}\Maze.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="maze.tape.Commands" />
</manifest>
</jar>
</target>
<target name="test" depends="compile">
<junit printsummary="on" fork="true" haltonfailure="yes">
<classpath refid="junit.class.path" />
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${test.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="run" depends="compile">
<java jar="dest-server/Maze.jar" fork="true"/>
</target>
</project>
Your test target is generating an xml file because you are using:
<formatter type="xml" />
when the attribute usefile is not used, the default value will be set and in this case, the value is "true".
You can set the attribute to false and the output will be displayed in the console.
We are having a problem when running unit tests using CPsuite and JMockit.
The tests run fine when executed in Eclipse, but if we use our Ant script to run all the tests (see script at the end of this question), we get the following exception:
Testcase: initializationError took 0 sec
Caused an ERROR
(class: mockit/internal/startup/JDK6AgentLoader, method: getVirtualMachineImplementationFromEmbeddedOnes signature: ()Lcom/sun/tools/attach/VirtualMachine;) Wrong return type in function
java.lang.VerifyError: (class: mockit/internal/startup/JDK6AgentLoader, method: getVirtualMachineImplementationFromEmbeddedOnes signature: ()Lcom/sun/tools/attach/VirtualMachine;) Wrong return type in function
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
at mockit.internal.startup.Startup.verifyInitialization(Startup.java:86)
at mockit.Invocations.<clinit>(Invocations.java:22)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
This only happens on Ant, and only if there is a class that uses JMockit in the CPSuite set.
Anyone know why are we getting this error?
The Ant Script:
<project name="chughtai.junit" default="run" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<!-- https://junit-anttask.dev.java.net/ -->
<!--
<taskdef name="junit2" classname="com.sun.ant.junit.JUnitTask">
<classpath>
<pathelement path="lib/junit-anttask.jar" />
<pathelement path="lib/junit-4.4.jar" />
</classpath>
</taskdef>
-->
<property environment="env"/>
<property file="junit.build.properties"/>
<filelist id="third-party_jars" dir="lib">
<file name="${ext.classpath}/bin/lib/j2ee.jar"/>
</filelist>
<path id="project.path">
<pathelement path="${env.JAVA_HOME}/lib/tools.jar"/>
<pathelement location="classes/"/>
<fileset dir="lib">
<include name="**/*.jar"/>
<include name="**/*.properties"/>
</fileset>
<dirset dir="${build.dir}">
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<pathelement location="${basedir}/junittestcases"/>
<filelist refid="third-party_jars"/>
<pathelement path="${ext.classpath}"/>
<pathelement location="${ext.classpath}/WEB-INF/classes"/>
</path>
<target name="init">
<mkdir dir="${prd.junit.test.report.dir}" />
<mkdir dir="${prd.junit.test.report.dir}/html" />
</target>
<!-- default target -->
<target name="run" depends="init">
<property name="myclasspath" refid="project.path"/>
<property name="java.class.path" refid="project.path"/>
<echo message="***Junit Controller Application***"/>
<echo message="basedir is ${basedir}"/>
<!--<echo message="${myclasspath}" />-->
<junit dir="${basedir}/junittestcases/" printsummary="yes" haltonfailure="no" fork="no" forkmode="once" reloading="false" maxmemory="1024m">
<jvmarg value="-Xms768M"/>
<jvmarg value="-Xmx1024M"/>
<jvmarg value="-XX:MaxPermSize=256M"/>
<sysproperty key="tests" value="${tests}"/>
<sysproperty key="java.class.path" value="${myclasspath}"/>
<formatter type="plain" usefile="true" extension=".txt" />
<formatter type="xml" />
<classpath refid="project.path"/>
<test name="${use.testcase}" haltonfailure="no" fork="false" todir="${prd.junit.test.report.dir}" if="use.testcase">
<formatter type="xml" />
</test>
</junit>
<!-- Generate the Unit Test reports -->
<junitreport todir="${prd.junit.test.report.dir}">
<fileset dir="${prd.junit.test.report.dir}">
<include name="*.xml" />
</fileset>
<report todir="${prd.junit.test.report.dir}/html" styledir="${xsl.templates}" format="frames">
<param name="build.number" expression="${app.build}" />
<param name="application.name" expression="${app.name}" />
</report>
</junitreport>
</target>
<target name="emma.report" depends ="" description="Creates 3 EMMA report formats based on the coverage data gathered.">
<if>
<available file="coverage.ec" />
<then>
<move file="coverage.ec" tofile="${coverage.dir}/junits.ec" overwrite="true"/>
</then>
</if>
<emma>
<report sourcepath="src" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
<!-- collect all EMMA data dumps (metadata and runtime)
[this can be done via nested <fileset> fileset elements
or <file> elements pointing to a single file]:
-->
<fileset dir="${coverage.dir}">
<include name="*.em" />
<include name="*.ec" />
</fileset>
<!-- for every type of report desired, configure a nested
element; various report parameters
can be inherited from the parent <report>
and individually overridden for each report type:
-->
<txt outfile="${coverage.dir}/coverage.txt" depth="package" columns="class,method,block,line,name" />
<xml outfile="${coverage.dir}/coverage.xml" depth="package" />
<html outfile="${coverage.dir}/coverage.html" depth="method" columns="name,class,method,block,line" />
</report>
</emma>
</target>
<target name="clean">
<delete file="${coverage.dir}/coverage.*" />
</target>
</project>
I am using Junit 4.10 with ANT 1.8.3 and Teamcity 7.0.2. I have set printsummary=withOutAndErr in my build.xml
When I run the build manually from ANT, the generated JUnit HTML report shows System.out statements, however; When I run the same build from Teamcity the System-out statements do not show up. What am I doing wrong?
Build.xml to reproduce the scenario:
Sample JUnit Tests
<property name="project_name" value="junitSamples"/>
<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="dist" location="dist"/>
<property name="lib" location="lib"/>
<property name="res" location="res"/>
<property name="reports" location="reports"/>
<!-- the names of various distributable files -->
<property name="jar_name" value="${project_name}.jar"/>
<property name="war_name" value="${project_name}.war"/>
<!-- top level targets -->
<target name="compile" depends="init" description="compile the source code " >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="dist" depends="compile" description="generate the distributable files " >
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/${jar_name}" basedir="${build}"/>
</target>
<target name="clean" description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
</target>
<target name="run-tests" depends="compile" description="run your test suite" >
<junit printsummary="true" haltonfailure="no" 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="frames" todir="${reports}\html\"/>
</junitreport>
</target>
<target name ="run" depends="" description="if this project can be run, run it" >
</target>
<!-- supporting targets -->
<target name="init" description="initialize the build environment" >
<!-- Create the time stamp -->
<tstamp/>
<!-- Create directory structures -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
<mkdir dir="${build}"/>
<mkdir dir="${dist}/lib"/>
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/>
</target>
<target name="all" depends="clean, test">
</target>