How can we run a junit plugin test using ant from eclipse, also from command prompt? I'm using Junit4.4.
The org.eclipse.test plugin provides a library.xml file that contains ant tasks for running plugin tests both in UI (ui-test target) and headless (core-test target) modes. Example of invoking the task below, you'll need to provide a few properties to suite your own environment and check the org.eclipse.test plugin version:
<property name="library-file"
value="${eclipse-home}/plugins/org.eclipse.test_3.2.0/library.xml" />
...
<ant target="ui-test" antfile="${library-file}"
dir="${eclipse-home}">
<property name="data-dir" value="${workspace}" />
<property name="plugin-name" value="${plugin-name}" />
<property name="classname"
value="com.example.MyTestSuite" />
<property name="junit-report-output" value="${results.dir}"/>
</ant>
Related
I have an testsuite of API testing in SOAP UI.
I want an HTML report of testcases results. I am using basic SOAP UI version. Give me a solution apart from SOAP UI Pro.
Yes, it is possible to generate Junit Style HTML reports using SoapUI Opensource Edition as well.
All you need to do is the execution of tests has to be done
use Apache-Ant software, more details on installing and configuring here
write build script
Here is the sample build script(build.xml):
Note that modify the SOAPUI_HOME(or define environment variable), soapui project file path, results directory path according to your environment.
<project basedir="." default="testreport" name="ant script for testing soapui project">
<property environment="env"/>
<property name="soapui.project" value="/app/demo-soapui-project.xml"/>
<property name="results.dir" value="/tmp/results"/>
<property name="reports.dir" value="${results.dir}/Reports"/>
<property name="html.dir" value="${reports.dir}/html"/>
<target name="execute.project">
<exec dir="${env.SOAPUI_HOME}" executable="testrunner.sh">
<arg line="-raj -f ${results.dir} ${soapui.project}" />
</exec>
</target>
<target name="testreport" depends="execute.project">
<mkdir dir="${reports.dir}"/>
<junitreport todir="${reports.dir}">
<fileset dir="${results.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${html.dir}" />
</junitreport>
</target>
</project>
and execute following command (run soapui project and generate report):
ant
There is also simple way (i.e., every thing configured and readily available envrionment) if you are willing to use this docker image.
Short video also available there on how to.
I am trying to integrate Sonar task in Ant build in Eclipse. SonarQube server is running successfully at the default port on localhost. On opening "http://localhost:9000/" in browser, SonarQube web interface is successfully opening.
Problem is when I am running Sonar task from Ant build file it is giving error "org.sonar.runner.impl.RunnerException: Unable to execute Sonar". That's it. No stacktrace is logged on console.
The sonar task in ANt build is defined as below:
<target name="sonar" depends="jcompile">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="<PathToAntPlugin>/lib/sonar-ant-task-2.2.jar" />
</taskdef>
<property name="sonar.projectDescription" value="Example application using Ant and Jacoco" />
<property name="sonar.sources" value="${basedir}/src" />
<property name="sonar.host.url" value="http://localhost:9000"/>
<property name="sonar.surefire.reportsPath" value="${reports.junit.xml.dir}" />
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<property name="sonar.jacoco.antTargets" value="run-tests" />
<property name="sonar.projectKey" value="<PathToMyProject>" />
<property name="sonar.projectVersion" value="1.0" />
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant"/>
</target>
Other details:
SonarQube Server 4.5,
sonar-ant-task-2.2.jar,
JDK 1.6.0_21,
Eclipse Kepler
Is there any comptability issue between the jdk, eclipse, sonar server or sonar ant jar? Is there any way to find the detail logs in order to debug the issue?
Apart from above issue, I am having other issue. When I am installing SonarCube plugin in eclipse, in Windows ->Preferences SonarCube is not coming. However, in installed software list in Eclipse it is listed. I have tried to run eclipse with -clean option but no success. Please let me know what could be the problem?
When we are running the build file from eclipse it is not giving full stack trace on console in some cases. Try to run the build file from the command prompt.
For example:
Open command prompt window and go to eclipse ant bin directory path(In my system it is C:\eclipse\plugins\org.apache.ant_1.9.6.v201510161327\bin) and from here run your build file using ant command.
C:\eclipse\plugins\org.apache.ant_1.9.6.v201510161327\bin>ant -buildfile [path_of_build_file]\build-test.xml
I know I am late, but this is to help who visits this with same problem
For the missing preferences, the Installation FAQ of Sonar says to do a restart with -clean argument.
I am researching replacements for Ant. I've looked at Gant and Gradle.
Is it possible to kick off a Gradle task from Ant? This is possible in Gant with a taskdef.
<taskdef
name = "gant"
classname = "org.codehaus.gant.ant.Gant"
classpathref = "classpath"
/>
<gant />
Is there something similar Gradle? I'm eager to start migrating from Ant to Gradle, but we have a large Ant infrastructure and any Gradle build scripts I create need to be callable from Ant.
Thanks!
Create a macrodef for gradle, call it just like any other task. Here is the setup and an example...
<!-- Gradle path stuff -->
<property environment="env" />
<condition property="gradle.executable" value="${env.GRADLE_HOME}/bin/gradle.bat" else="${env.GRADLE_HOME}/bin/gradle">
<os family="windows" />
</condition>
<!-- Macro def, gives us an ant 'gradle' task-->
<macrodef name="gradle">
<attribute name="task" />
<sequential>
<exec executable="${gradle.executable}" dir="." failonerror="true">
<arg value="#{task}" />
</exec>
</sequential>
</macrodef>
Example of using the macro def
<!-- Example, call grade with new macro -->
<target name="example">
<gradle task="build" />
</target>
Instead of switching build technology, why not use a combination of ivy and groovy to extend the capabilities of your existing ant builds?
An example is the following posting:
Parse HTML using with an Ant Script
BTW I'm a big fan of Gradle, however, like you I have to live with and support a large ANT legacy :-)
Actually I want to do the same thing and where implemented by calling a sh file and then the sh was calling the gradle but it was too much around the bush and finally the following code made it to work cool..
Hope this will help you..
<property environment="env" />
<property name="gradle.wrapper.executable" location="${env.GRADLE_HOME}/bin/gradle" />
<target name="dependencies-report" description="Creates a text file report of the depdency tree">
<exec executable="${gradle.wrapper.executable}" dir=".">
<arg value="dependencyReport" />
</exec>
</target>
Gradle doesn't offer an Ant task to run a Gradle build from Ant. What you could do is to invoke a Gradle command (like gradle build) from Ant.
In terms of Ant integration, Gradle offers two features: Importing Ant builds, and reusing Ant tasks.
Gradle is very different from Gant. Gradle is an entire new build system; Gant is a thin layer above Ant.
Problem description:
The setup is executing Ant build script with TestNG target, which then loads testng.xml file. There is a possibility to specify listeners in both Ant file and testng.xml.
The questions arising are following:
Will both set up ways be supported? Will all the listeners specified in both configuration location be used during test execution?
Will any of listeners be prioritized over another? If yes, how?
Sample set up:
Ant file:
<project>
<property name="classes.dir" path="<my_classes_dir>" />
<property name="test.dir" path="<my_test_dir>" />
<target name="run-test">
<testng useDefaultListeners="false"
listeners="org.testng.reporters.EmailableReporter, org.testng.reporters.XMLReporter, com.example.MyCustomReporter">
<classpath>
<path path="${classes.dir}" />
</classpath>
<xmlfileset dir="${test.dir}" includes="testng.xml" />
</testng>
</target>
</project>
TestNG.xml:
<suite name="MyTestSuite">
<listeners>
<listener class-name="com.example.MyListener" />
<listener class-name="org.testng.reporters.FailedReporter" />
</listeners>
<test name="MyTest1">
<classes>
<class name="com.example.MyTest1" />
</classes>
</test>
</suite>
Background:
I have to support existing project which uses set up similar to the one described above. The Ant build file disables default reporters. Without touching Ant build file, I would like to specify additional report listeners (FailedReporter and/or any custom ones) for my tests in testng.xml.
I believe all listeners should be run, in your build file as well as in your testng.xml.
The testng.xml listeners would be executed second.
If the same listener is listed in both, build file and testng.xml, it would be executed twice.
This is based on my experience with Maven, but I guess, with ant it should be the same.
Also the order of listeners specified in testng.xml cannot be guaranteed in case both are implementing the same set of interfaces.
Hope it helps.
I have the following Sonar Ant target defined:
<target name='sonar'>
<property name='sonar.sources' value='${src.dir}'/>
<property name='sonar.tests' value='${test.src.dir}'/>
<property name='sonar.binaries' value='build/classes'/>
<path id='jars'>
<fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/>
<fileset dir='build/lib/test' includes='*.jar'/>
</path>
<pathconvert property='sonar.libraries' refid='jars' pathsep=','/>
<exec executable='p4' outputproperty='p4.P4CLIENT'>
<arg value='set'/>
<arg value='P4CLIENT'/>
</exec>
<propertyregex
property='p4client'
input='${p4.P4CLIENT}'
regexp='P4CLIENT=([^ ]+) *.*'
replace='\1'/>
<propertyregex
property='sonar.timestamp'
input='${build.time}'
regexp='_'
replace='T'/>
<sonar:sonar key='com.netflix:${module.name}' version='${p4client}#${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/>
<property name='sonar.dynamicAnalysis' value='reuseReports'/>
<property name='sonar.emma.reportPath' value='${coverage.dir}'/>
</target>
When I run 'ant sonar' and bring up Sonar in my browser, I see info about the classes in the src directory, but nothing about the stuff in the test directory.
If I add ${test.src.dir} to sonar.sources and not set sonar.tests, I see some info about the test classes, but Sonar still reports 0 Test Successes.
How do I get it so I can drill down to each test method and their stats?
For anyone else that runs across this issue, I finally got Sonar to report on our Emma Code coverage. The first problem was that the Emma plugin did not come with the version of Sonar I was using (3.1.1). I had to download it and install it to the extensions/plugins directory of Sonar and restart it.
Then I had to set the following properties in my build.xml:
<property name="sonar.core.codeCoveragePlugin" value="emma" />
<property name="sonar.emma.reportPath" value="${coverage.dir}" />
After this, I atleast saw the following output after running the Sonar ant task:
[sonar:sonar] 13:41:49.705 WARN org.sonar.INFO - No coverage (*.ec) file found in /my/local/path
[sonar:sonar] 13:41:49.708 WARN org.sonar.INFO - No metadata (*.em) file found in /my/local/path
After some digging, I found that inside of the Sonar Emma plugin, it is hard-coded to look for a .ec (coverage) file and a .em (metadata) file. Unfortunately, my coverage file had a .emma extension as did my metadata file and I was unable to rename them as it would break other functionality. So I wrote the following Ant task to copy the files to match the naming standard that the Sonar Emma plugin expects.
<target name="createEmmaFilesWithSonarNamingStandard" depends="defineAntContribTasks">
<if>
<available file="${coverage.dir}/metadata.emma" />
<then>
<copyfile src="${coverage.dir}/metadata.emma" dest="${coverage.dir}/metadata.em" />
</then>
</if>
<if>
<available file="${coverage.dir}/coverage.emma" />
<then>
<copyfile src="${coverage.dir}/coverage.emma" dest="${coverage.dir}/coverage.ec" />
</then>
</if>
</target>
After running this again, I came across a new problem:
org.sonar.api.utils.SonarException: java.io.IOException: cannot read [/my/local/path/build/coverage/metadata.em]: created by another EMMA version [2.0.5312]
After some more digging, I found that the Sonar Emma 1.0.1 plugin was compiled against Emma 2.0.5312 and the Sonar Emma 1.1 and 1.2.x against Emma version 2.1.5320 as stated on the Sonar Emma plugin page.
I downloaded the 2.1.5320 version of Emma, replaced both emma.jar as well as emma_ant.jar in my Ant lib directory. After a clean re-compile and test, I was able to re-run the Sonar Ant task and have my code coverage reflected on Sonar.
The property 'sonar.surefire.reportsPath' needs to be defined before the definition of the sonar target.
The following definition gets the test info exported (although it's still not exporting coverage info):
<property name='sonar.surefire.reportsPath' value='${test.dir}'/>
<property name='sonar.dynamicAnalysis' value='reuseReports'/>
<property name='sonar.emma.reportPath' value='${coverage.report.dir}'/>
<target name='sonar'>
<property name='sonar.sources' value='${src.dir}'/>
<property name='sonar.tests' value='${test.src.dir}'/>
<property name='sonar.binaries' value='${build.dir}'/>
<path id='jars'>
<fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/>
<fileset dir='${ivy.lib.dir}/test' includes='*.jar'/>
</path>
<pathconvert property='sonar.libraries' refid='jars' pathsep=','/>
<exec executable='p4' outputproperty='p4.P4CLIENT'>
<arg value='set'/>
<arg value='P4CLIENT'/>
</exec>
<propertyregex
property='p4client'
input='${p4.P4CLIENT}'
regexp='P4CLIENT=([^ ]+) *.*'
replace='\1'/>
<propertyregex
property='sonar.timestamp'
input='${build.time}'
regexp='_'
replace='T'/>
<sonar:sonar key='com.netflix:${module.name}' version='${p4client}#${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/>
</target>