I am using a build.xml(ant) and code looks as follows,
<junit fork="yes" dir="." >
----------
---------
<for list="1,2,3,4,5,6" param="Val">
<env key="environment" value="${Val}" />
<batchtest fork="yes" todir="${junitreport.todir}">
<fileset dir="src/java">
<include name="TestOne.java" />
<include name="TestTwo.java" />
</fileset>
</batchtest>
</for>
</junit>
while running this i get the following error,
junit doesn't support the nested "for" element.
Is there any other way to achieve this loop in junit?
Please help.
Swap the <for> and the <junit> elements so <for> is on the outside and <junit> is on the inside:
<for list="1,2,3,4,5,6" param="Val" delimiter=",">
<sequential>
<junit ...>
<!-- Use an at-sign to reference the "param" from "for". -->
<env key="environment" value="#{Val}" />
</junit>
</sequential>
</for>
Note, that Val is referenced as #{Val} with an at-sign (#), not a dollar sign ($).
Related
I'm trying to execute a few junit test suits with ant.
Here's my folder structure
bin
lib
src
test
build.xml
First of all I compile all files in source location, later on java files in test folder.
Whole structure of test folder (compiled .class files) are saved in bin folder which looks like this inside.
bin-test-alltests
|
-suites - SetupSuite.class
- StartSuite.class
in allTests folder are tests that are used in suites in suites folder
I'm trying to start those suites but constantly I've got an error:
ant junit java.lang.noclassdeffounderror wrong name
I'm pretty sure that's something wrong with the class path but I don't know what. I've tried to changed
<test name="SetupSuite"/>
to
<test name="SetupSuite.class"/>
and I get another error:
java.lang.ClassNotFoundException: SetupSuite.class
Here's my build.xml file
<project name="MyTest" basedir=".">
<!--Common properties -->
<property name="src.dirname" value="src" />
<property name="test.dirname" value="test" />
<property name="lib.dirname" value="lib" />
<property name="bin.dirname" value="bin" />
<property name="src.encoding" value="utf8" />
<property name="src.version" value="1.7" />
<property environment="env" />
<!-- Paths for MyTest -->
<property name="MyTest.dir" value="${basedir}" />
<property name="MyTest.src.dir" value="${MyTest.dir}\${src.dirname}" />
<property name="MyTest.test.dir" value="${MyTest.dir}\${test.dirname}" />
<property name="MyTest.dest.dir" value="${MyTest.dir}\${bin.dirname}" />
<property name="MyTest.lib.dir" value="${MyTest.dir}\${lib.dirname}" />
<path id="classpath">
<pathelement location="${MyTest.lib.dir}\junit.jar" />
<pathelement location="${MyTest.test.dir}\test\suites\" />
</path>
<target name="compile-MyTest-src" >
<myjavac srcdir="${MyTest.src.dir}" destdir="${MyTest.dest.dir}" classpath="{MyTest.lib.dir}\junit.jar"/>
</target>
<target name="compile-MyTest-test" depends="compile-MyTest-src">
<path id='libs'>
<fileset dir= "${MyTest.lib.dir}\" includes="**/*.jar"/>
</path>
<myjavac srcdir="${MyTest.test.dir}\" destdir="${MyTest.dest.dir}" classpathref = 'libs'/>
</target>
<target name="execute-tests" depends="compile-MyTest-src,compile-MyTest-test">
<junit printsummary="yes" haltonfailure="no" showoutput="yes">
<formatter type = "brief" usefile = "false" />
<classpath refid="classpath" />
<test name="SetupSuite"/>
</junit>
</target>
<!-- General compiler settings -->
<presetdef name="myjavac">
<javac classpathref="classpath" debug="on" includeantruntime="false" encoding="${src.encoding}" source="${src.version}" target="${src.version}" />
</presetdef>
</project>
Solved. I had to add hamcrest-core-1.3.jar file to classpath
You need to set test name to full name of your SetupSuite:
<test name="alltests.suites.SetupSuite"/>
I have two JDBC flows in Mule 3.2.0, one using MySQL database and other using SQLServer database.
<mule ...
<spring:bean id="MySQL-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName"
value="com.mysql.jdbc.Driver" />
<spring:property name="url"
value="jdbc:mysql://host:port/schema" />
</spring:bean>
<jdbc:connector name="MySQL-jdbcConnector"
dataSource-ref="MySQL-jdbcDataSource" pollingFrequency="${MySQL.db.poll}"
transactionPerMessage="false">
<jdbc:query key="read" value="${MySQL.db.jdbc_query}" />
</jdbc:connector>
<flow name="MySQL-flow">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="MySQL-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN"/>
<property key="receiveMessageInTransaction" value="true"/>
</jdbc:inbound-endpoint>
<vm:outbound-endpoint path="path" connector-ref="first-level">
<message-properties-transformer scope="outbound">
<add-message-property key="identifier" value="MySQL"/>
</message-properties-transformer>
<vm:transaction action="NONE"/>
</vm:outbound-endpoint>
</flow>
</mule>
And
<mule ...
<spring:bean id="SQLServer-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<spring:property name="url"
value="jdbc:sqlserver://host:port;databaseName=schema" />
</spring:bean>
<jdbc:connector name="SQLServer-jdbcConnector"
dataSource-ref="SQLServer-jdbcDataSource" pollingFrequency="${SQLServer.db.poll}"
transactionPerMessage="false">
<jdbc:query key="read" value="${SQLServer.db.jdbc_query}" />
</jdbc:connector>
<flow name="SQLServer-flow">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="SQLServer-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN"/>
<property key="receiveMessageInTransaction" value="true"/>
</jdbc:inbound-endpoint>
<vm:outbound-endpoint path="${sv.vm.queue.name}" connector-ref="first-level-xform">
<message-properties-transformer scope="outbound">
<add-message-property key="${sv.vm.msg.identifier}" value="SQLServer"/>
</message-properties-transformer>
<vm:transaction action="NONE"/>
</vm:outbound-endpoint>
</flow>
</mule>
When I deploy any one of these floes in mule-deploy.properties, it runs ok. But when I deploy both of these flows at the same time, none of them works. I do not get any error or exception, but it seems like none of these flows run.
Any ideas what might be wrong? Probably something related to JDBC transactions?
if you have 2 different flows in same application .. then remove :-
<spring:bean id="SQLServer-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<spring:property name="url"
value="jdbc:sqlserver://host:port;databaseName=schema" />
</spring:bean>
<jdbc:connector name="SQLServer-jdbcConnector"
dataSource-ref="SQLServer-jdbcDataSource" pollingFrequency="${SQLServer.db.poll}"
transactionPerMessage="false">
<jdbc:query key="read" value="${SQLServer.db.jdbc_query}" />
</jdbc:connector>
from any of the flow ... Since it is declared as global ... it can be used from any of the flow in the application .. what I mean is .. just remove the above line of code from one of the flow ... since you have declared in both the flow I guess it's a duplicate and not required to place in each and every flow ... and yes just mention the reference connector-ref="SQLServer-jdbcConnector" in both the mule flow ... ex:-
<jdbc:inbound-endpoint queryKey="read"
connector-ref="SQLServer-jdbcConnector">
Here is my build.xml. Here all the paths are mentioned.
In report all the percentages are 0(ZERO).
And It is also prompting me that "Have you mentioned the specified source directory"
Please suggest where is the mistake.
Either I have to change the build.xml or have to perform some steps.
First I ran all the junit test cases, then stoped the server and then run the build.xml as ant-build.
<project name="RFM2" default="cobertura_REPORT">
<property name="BASEDIR" value="D:/SIT/busnessservice" />
<property name="cobertura.dir" value="D:/SIT/JUNIT_jars/cobertura-1.9.1" />
<property name="src.dir" value="${BASEDIR}/src" />
<property name="build.dir" value="${BASEDIR}/build" />
<property name="dist.dir" value="${BASEDIR}/dist" />
<property name="lib.dir" value="D:/SIT/JUNIT_jars/jars" />
<property name="report.dir" value="${BASEDIR}/reports" />
<property name="cobertura.ser.file" value="${cobertura.dir}/cobertura.ser" />
<property name="server.ser.file" value="D:/Program Files/cobertura.ser" />
<property name="instrumentedDir" value="${cobertura.dir}/instrument" />
<property name="junit.data.dir" value="${report.dir}/junit/data" />
<property name="junit.report.dir" value="${report.dir}/junit/html" />
<property name="junit.dir" value="D:/SIT/JUNIT_jars/jars" />
<property name="test.dir" value="D:/SIT/JUNITTESTFILES" />
<!--class path for cobertula -->
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura-1.9.4.1.jar" />
<include name="*.jar" />
</fileset>
</path>
<!--class path for JUNIT -->
<path id="junit.classpath">
<fileset dir="${junit.dir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${junit.dir}/junit-4.1.jar" />
<pathelement location="${BASEDIR}/bin" />
<path refid="cobertura.classpath" />
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<!-- PATH FOR LIB -->
<path id="lib.classpath">
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<path id="runtime.classpath">
<pathelement location="${build.dir}" />
<path refid="lib.classpath" />
</path>
<!--Initialization -->
<target name="init">
<mkdir dir="${dist.dir}" />
</target>
<!-- Clean files-->
<target name="clean" description="Remove all generated files.">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Compile the java file -->
<!--Instrument the files -->
<target name="cobertura_instrument">
<cobertura-instrument todir="${instrumentedDir}" datafile="${server.ser.file}">
<fileset dir="${lib.dir}">
<include name="businessServices.jar" />
</fileset>
</cobertura-instrument>
<!-- Copy cobertula.ser file in server-->
</target>
<!--copy the instrumented file in class file-->
I have removed this block as I think it is not getting used .
But still my report is getting generated with zero percentage.
<!--Make EAR-->
<target name="making ear">
<echo>come in making ear</echo>
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war" />
</ear>
</target>
<!--Run the JUNIT Test Case-->
<target name="runJunitTest">
<junit fork="yes" dir="${test.dir}" failureProperty="test.failed">
<!--
Specify the name of the coverage data file to use.
The value specified below is the default.
-->
<sysproperty key="net.sourceforge.cobertura.datafile" file="${server.ser.file}" />
<classpath location="${instrumentedDir}" />
<classpath refid="junit.classpath" />
<classpath refid="cobertura.dir" />
<formatter type="plain" usefile="false" />
<formatter type="xml"/>
<test name="${test.dir}/ColorConfigurationTest" />
<batchtest todir="${report.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</target>
<!--rEPORTING-->
<target name="cobertura_REPORT">
<delete dir="${report.dir}" />
<mkdir dir="${report.dir}" />
<cobertura-report srcdir="${src.dir}" format="html" destdir="${report.dir}" datafile="${server.ser.file}">
</cobertura-report>
</target>
</project>
<!--Make EAR-->
<target name="making ear">
<echo>come in making ear</echo>
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war" />
</ear>
</target>
<!--Run the JUNIT Test Case-->
<target name="runJunitTest">
<junit fork="yes" dir="${test.dir}" failureProperty="test.failed">
<!--
Specify the name of the coverage data file to use.
The value specified below is the default.
-->
<sysproperty key="net.sourceforge.cobertura.datafile" file="${server.ser.file}" />
<classpath location="${instrumentedDir}" />
<classpath refid="junit.classpath" />
<classpath refid="cobertura.dir" />
<formatter type="plain" usefile="false" />
<formatter type="xml"/>
<test name="${test.dir}/ColorConfigurationTest" />
<batchtest todir="${report.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</target>
I noticed one thing that should be easy to correct - that doesn't match the Cobertura doc or my working copy. Hopefully this will fix your problem.
Your JUnit task references <classpath refid="cobertura.dir" /> but the cobertura.dir is not a path id, it is the name of a property pointing to your cobertura directory. (IntelliJ IDEA flagged it in red, which caught my eye!)
In my script, I have:
Then my JUnit task references the cobertura.classpath like so:
<classpath refid="cobertura.classpath" />
Hope this helps!
I have a Flex AIR project that compiles and runs in Flex Builder 4.6. I'm trying to create an Ant script that will build the project. On these lines I get these errors:
_process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
_process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
_process.addEventListener(NativeProcessExitEvent.EXIT, onNativeProcessExit);
I'm getting this error:
[mxmlc] MyClass.as(190): col: 44 Error: Access of possibly undefined property STANDARD_OUTPUT_DATA through a reference with static type Class.
[mxmlc] _process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
[mxmlc] ^
[mxmlc] MyClass.as(191): col: 44 Error: Access of possibly undefined property STANDARD_INPUT_PROGRESS through a reference with static type Class.
[mxmlc] _process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
From what I can tell, these are defined in frameworks/libs/air/airglobal.swc. I think I'm including that with the compiler.external-library-path element below.
The compile target of my build.xml ant script looks like this:
<target name="compile" depends="init">
<mxmlc file="${MAIN_SOURCE_FILE}" output="${DEPLOY_DIR}/${APP_NAME}.swf"
services="${APP_ROOT}/services/flex/services-config.xml">
<swf-version>13</swf-version>
<locale>en_US</locale>
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${APP_ROOT}/../MyLib/src"/>
<source-path path-element="${APP_ROOT}/src"/>
<compiler.external-library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs/air" />
</compiler.external-library-path>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
<include name="../bundles/{locale}" />
</compiler.library-path>
<compiler.library-path dir="${APP_ROOT}" append="true">
<include name="libs" />
<include name="libs/player" />
</compiler.library-path>
<define name="CONFIG::debugging" value="false"/>
<compiler.debug>false</compiler.debug>
</mxmlc>
I think you want to change the <load-config> to be one of these:
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
or
<load-config filename="${FLEX_HOME}/frameworks/airmobile-config.xml"/>
I am modifying a Nant build script to run some unit tests. I have different targets for locally run tests and tests to be run on team city.
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<call target="do-unit-tests"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<call target="do-unit-tests"/>
</target>
in the target do-unit-tests I set up which test assemblies are run by setting a property and calling for NCover to do a code coverage run as follows:
<target name="do-unit-test">
<property name="test.assemblies" value="MyProject.dll">
<call target="do-unit-test-coverage" />
</target>
<target name="do-unit-test-coverage">
<ncover <!--snip -->
commandLineArgs="${test.args}"
<!--snip-->
</ncover>
</target>
As you can see in the ncover part I need a property called "test.args". This property depends on "test.assemblies"
ie: <property name="test.args" value="${test.assemblies} <!--snip -->" />
test.args needs to be set up differently between the locally run unit test and the one on team city...so I'm trying to figure out how to set this up.
if i put the property for test.args in "do-unit-test" after the property "test.assemblies" I can't specify one test.args if do-unit-test is called by run-unit-tests and another for run-unit-tests-teamcity.
I've been trying to do something like the following in "do-unit-test":
<if test="${target::exists('run-unit-tests-teamcity')}">
<property name="test.args" value="..." />
</if>
but obviously that doesn't work because the target will always exist.
What I'd like then is to test if my current target do-unit-test has been called by run-unit-tests-teamcity
Is this possible? I can't see it in the Nant documentation? Since its not there it either means that it will be a feature in the future or that I'm not understanding how things are specified in a Nant build script.
You can define properties in one target, and use their values in the other... For example, you can define
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<property name="test.extratestargs" value="foo,bar,baz"/>
<call target="do-unit-tests"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<property name="test.extrtestargs" value="foo,baz,quux,xyzzy"/>
<call target="do-unit-tests"/>
</target>
<target name="do-unit-test-coverage">
<property name="test.args" value="${test.assemblies} ${test.extratestargs} <!--snip -->" />
<ncover <!--snip -->
commandLineArgs="${test.args}" >
<!--snip-->
</ncover>
</target>
Or if you need them to be structured completely differently, not just have some different values, take advantage of the fact that the property substitution is delayed:
<?xml version="1.0"?>
<project name="nanttest">
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<property name="test.args" value="foo bar -assembly ${test.assemblies} baz" dynamic="true"/>
<call target="do-unit-test"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<property name="test.args" value="foo,baz,quux /a:${test.assemblies} xyzzy" dynamic="true"/>
<call target="do-unit-test"/>
</target>
<target name="do-unit-test-coverage">
<echo message="test.executable = ${test.executable}, test.args = ${test.args}" />
</target>
<target name="do-unit-test">
<property name="test.assemblies" value="MyProject.dll"/>
<call target="do-unit-test-coverage" />
</target>
</project>
user#host:/tmp/anttest$ nant run-unit-tests
[...snip...]
run-unit-tests:
do-unit-test:
do-unit-test-coverage:
[echo] test.executable = tools\nunit\nunit-console.exe, test.args = foo bar -assembly MyProject.dll baz
BUILD SUCCEEDED
Total time: 0 seconds.
user#host:/tmp/anttest$ nant -D:teamcity.dotnet.nunitlauncher=nunitlauncher run-unit-tests-teamcity
[...snip...]
run-unit-tests-teamcity:
do-unit-test:
do-unit-test-coverage:
[echo] test.executable = nunitlauncher, test.args = foo,baz,quux /a:MyProject.dll xyzzy
BUILD SUCCEEDED
Total time: 0 seconds.
If you really, really just need to know if you're running in TeamCity, then this should help:
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<property name="running.in.teamcity" value="true"/>
<call target="do-unit-tests"/>
</target>
I've managed to solve the problem. I don't know if it's the best solution but it is a solution.
I set a property called test.type and then use an if statement to determine which target it came from.
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<property name="test.type" value="unit-tests" />
<call target="do-unit-tests"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<property name="test.type" value="unit-tests-teamcity" />
<call target="do-unit-tests"/>
</target>
<target name="do-unit-test">
<property name="test.assemblies" value="MyProject.dll">
<call target="do-unit-test-coverage" />
</target>
<target name="do-unit-test-coverage">
<if test="${test.type=='unit-tests'}">
<property name="test.args" value="${test.assemblies} ..."/>
</if>
<if test="${test.type=='unit-tests-teamcity'}">
<property name="test.args" value="... ${test.assemblies}"/>
</if>
<ncover <!--snip -->
commandLineArgs="${test.args}"
<!--snip-->
</ncover>
</target>