Introduction
Ant must perform the following steps in the specified order to analyze your project with Jtest:
- Register the Parasoft build listener.
- Compile the project.
- Run the Jtest task.
Running Static Analysis
To perform static analysis on your code:
- Ensure that the Jtest Plugin for Maven is set up (see Configuring the Jtest Plugin for Ant).
- Ensure that the target you execute has the jtest task is configured in it.
- Add the Parasoft listener to you command line with the
-listener
switch or configure thejtest:listener
task in your target. Build your project with Ant. Your command line may resemble the following:
ant -lib PATH/TO/jtest-ant-plugin.jar -listener com.parasoft.Listener myTarget
The above example the Jtest Plugin for Ant is added to the command line, but you can deploy the JAR file in the Ant's lib directory (see Initial Setup).
By default, test sources are excluded from analysis. To analyze test code, disable the excludeTestSources
option; see Jtest Goals Reference for Ant.
Executing and Collecting Coverage for Unit Tests
You can include unit test results in the Jtest report by running your tests with tthe jtest and agent tasks, and the dedicated Unit Tests
built-in test configuration:
- Ensure that the Jtest Plugin for Maven is set up (see Configuring the Jtest Plugin for Ant).
- Ensure that the target you execute to run your tests has the following configured in it:
- the jtest task
- the junit task wrapped with the Jtest agent task
- the dedicatedUnit Tests
built-in test configuration - Add the Parasoft listener to you command line with the
-listener
switch or configure thejtest:listener
task in your target. Build your project with Ant. Your command line may resemble the following (the
jtest.coverage.skip
option allows you to skip collecting coverage):ant -lib PATH/TO/jtest-ant-plugin.jar -listener com.parasoft.Listener buildTestAnalyze
By default, Jtest collects coverage data for executed tests. To disable collecting coverage, enable the jtest.coverage.skip
option (see Jtest Tasks Reference for Ant for details).
About the agent
Task
Collecting coverage with the Java agent is the recommended way of collecting coverage data with Jtest. The agent task, which allows runtime bytecode instrumentation (without modification of .class files) must be configured in the appropriate target. The following example shows the build script with the required tasks configured in one target:
<project name="agent-sample" default="buildTestAnalyze" xmlns:jtest="antlib:com.parasoft.jtest.plugin.ant"> <!-- sources directory containing both tests and application source code. Usually these sources are not placed in one directory. --> <property name="sources" value="src"/> <!-- classes directory --> <property name="classes" value="bin"/> <target name="buildTestAnalyze"> <!-- compiling sources --> <javac srcdir="${sources}" destdir="${classes}"/> <!-- instrumenting bytecode --> <!-- run tests --> <jtest:agent> <!-- Following attributes will be set: haltonerror="no" haltonfailure="no" fork="yes" If agent task skipped nested task will be executed without any config changes. --> <junit> <!-- Formatter element will be set as following: <formatter type="xml"/> If different formatter type has been set it will get overridden. If formatter has been configured by classname it will be left as it is. --> <classpath> <pathelement location="${classes}"/> </classpath> <batchtest> <fileset dir="${classes}" includes="**/*Test.class"/> </batchtest> </junit> <coverage> <includes> <fileset dir="${classes}" /> </includes> <testIncludes> <include>**/*Test.class</include> </testIncludes> </coverage> </jtest:agent> <!-- analysis --> <jtest:jtest/> </target> </project>
Collecting Application Coverage
Jtest's coverage agent allows you to collect coverage data during manual or automated tests performed on a running application. See Application Coverage for information about collecting application coverage with Jtest.
Disabling Coverage Data Collection
You can disable collecting coverage in one of the following ways:
- Set the
skip
parameter to skip collecting coverage (this will not disable Jtest execution). - Run Ant with the following
-D
option:-Djtest.skip=true
- Configure the following project property:
<property name="jtest.skip" value="true"/>
(make sure the subprojects inherit this property if the Jtest tasks were configured there).