In this section:
The following tutorial will guide you through collecting application coverage with the Jtest. It includes information about basic topics, such as running the server and deploying applications, so that beginners and advanced users can benefit.
Web Application Coverage can be collected on any server that can accept Java Agents. The following requirements are only necessary to complete this tutorial:
[INSTALL]/examples
directory.Build the WAR file. The application must be packaged into a WAR file (Web Application Archive) on the server. Use the maven-war-plugin shipped with Jtest to package the application. The plugin automatically builds applications with the correct WAR structure. Execute the following command in the application directory:
mvn clean install |
Deploy the application to an application server. See Deploying Example to Tomcat, Deploying Example to WildFly/JBoss and Deploying Example to Oracle WebLogic for information about deploying the Calculator example to different application servers.
There are many ways to deploy application servers, but in this tutorial, we demonstrate how to deploy remotely using the Tomcat Manager web application.
Add a new user to the server by opening [Apache Tomcat Installation Directory]/conf/tomcat-users.xml and add the following line in the <tomcat-users>
section:
<user username="tomcat" password="tomcat" roles="tomcat, manager-gui"/> |
Run the server by executing the following command:
Windows
[Your apache-tomcat installation directory]/bin/startup.bat |
Linux
[Your apache-tomcat installation directory]/bin/startup.sh |
Open the following URL in a browser and enter the username and password set in step 1 (tomcat/tomcat):
http://localhost:8080/manager/html |
Click Deploy; the application will be available at the following URL:
http://localhost:8080/calculator |
There are many ways to deploy WildFly/JBoss application servers, but we demonstrate deployment in this tutorial by using the JBoss web console. These instructions can be applied to JBoss AS 7.1.1, JBoss EAP 6.4, and WildFly 8.2 and 9.0 servers.
Add a new user to the server by running the add-user script on Windows:
[JBoss installation directory]/bin/add-user.bat |
Choose Management User when prompted to choose a type of user:
What type of user do you wish to add? a) Management User (mgmt-users.properties) b) Application User (application-users.properties) (a): a |
Enter a username and password when prompted leaving the Realm field blank:
Enter the details of the new user to add. Realm (ManagementRealm) : Username : admin Password : 1adm-adm-adm |
Run the server by executing the following script:
[JBoss installation directory]/bin/standalone.bat |
Open the following URL in a browser and enter the username and password specified in step 3 (admin/1adm-adm-adm):
http://localhost:9990/console/App.html#deployments |
Enabled the Calculator.war file in the Deployments list and open the following URL in a browser:
http://localhost:8080/Calculator |
There are many ways to deploy WebLogic application server, but in this tutorial, we demonstrate how to deploy remotely using the Admin Console. This scenario has been verified with versions 12.2.1 and 10.3.6.
This tutorial assumes that you have already installed the WebLogic server and created your server domain.
Execute the following command in the example application’s main directory:
mvn package jtest:monitor |
The goal generates the monitor.zip package, which contains artifacts necessary for collecting application coverage.
javaagent
VM ArgumentExtract the contents of the monitor.zip package to the server machine and run the agent.bat (Windows) or agent.sh (Linux) script. This will generate the javaagent flag that will be printed to the console.
Your javaagent
flag may resemble the following:
-javaagent:"E:\Parasoft\JTest\examples\calculator\target\jtest\monitor\monitor\agent.jar"=settings="E:\Parasoft\JTest\examples\calculator\target\jtest\monitor\monitor\agent.properties",runtimeData="E:\Parasoft\JTest\examples\calculator\target\jtest\monitor\monitor\runtime_coverage" |
Collect runtime data from your application server: Tomcat, WildFly/JBoss or Oracle WebLogic.
Open the script file:Windows
[Your apache-tomcat installation directory]/bin/catalina.bat |
Linux
[Your apache-tomcat installation directory]/bin/catalina.sh |
Place the javaagent
flag at the beginning of the script.
Windows
if "%1"=="stop" goto skip_instrumentation set JAVA_OPTS=%JAVA_OPTS% [generated javaagent flag] :skip_instrumentation |
Linux
if [ "$1" = "start" -o "$1" = "run" ]; then export JAVA_OPTS="$JAVA_OPTS [generated javaagent flag]" fi |
The |
Restart the server and open the following URL in a browser:
http://localhost:8080/Calculator |
The Jtest Agent will write runtime data according to the runtimeData property of the -javaagent
flag generated by the mvn package jtest:monitor
goal. By default, the runtime data be written to the [path to monitor dir]/monitor/runtime_coverage
directory.
Standard Java hierarchical class loaders are not suitable for J2EE servers because all JAR files are always loaded, whether they are used or not; the application cannot load JAR files on demand. Additionally, an adequate solution for restricting visibility between JAR files is not available, which frequently causes conflicts between two versions of one library. This also leads to the creation of big class loaders that contain everything.
JBoss and WildFly servers use JBoss Modules to overcome these challenges. The implementation of modular, non-hierarchical class loading is also the basis of JBoss OSGi and JBoss Java EE implementations.
The advantages of this class loader, however, introduces new problems in terms of collecting runtime data from these servers. The Jtest Agent library must be visible to application classes, but it is prevented by JBoss Modules. This is one reason for adding the -javaagent
flag. Failing to do so will return ClassNotFoundException
.
For this reason, the jboss.modules.system.pkgs
system property should also be used. But there is another problem: JBoss sets this flag in its own scripts. This behavior complicates integration between JBoss and the Jtest Agent because these scripts may overwrite previously set scripts.
Add the -javaagent
flag to the startup script.
Windows
a) Open [Your jboss installation directory]/bin/standalone.conf.bat
and add the javaagent
flag to JAVA_OPTS at the end of the file:
set "JAVA_OPTS=%JAVA_OPTS% [generated javaagent flag]" |
- Leave ":JAVA_OPTS_SET
" as the last line in the file.
- Place the -javaagent
flag in one line (it cannot be split).
- Add the -XX:-UseSplitVerifier
flag to JAVA_OPTS for servers working on Java 7.
b) Add javaagent
classes to jboss.modules.system.pkgs
settings by changing the following section from:
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman" |
to
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman,com.parasoft.jtest.instrumentation,shaded.com.parasoft.jtest.runtime" |
c) Restart the server using the standalone.bat script.
Linux
a) Open [Your jboss installation directory]/bin/standalone.conf
and add the javaagent
flag to JAVA_OPTS at the end of the file:
set "JAVA_OPTS=$JAVA_OPTS [generated javaagent flag]" |
- Place the -javaagent
flagin one line (it cannot be split).
- Add the -XX:-UseSplitVerifier
flag to JAVA_OPTS for servers working on Java 7.
b) Add javaagent
classes to jboss.modules.system.pkgs
settings by changing the following section from:
JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman" |
to
JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,com.parasoft.jtest.instrumentation,shaded.com.parasoft.jtest.runtime" |
c) Restart the server using the standalone.sh
script.
Open to the following URL in a web browser:
http://localhost:8080/Calculator/ |
The Jtest Agent will create a runtimeData.data
file in the Jtest target maven directory (target/jtest).The location is written into the .json data file, so you do not need to remember it.
The jboss.modules.system.pkgs property does not need to be set for older versions of JBoss.
Windows
Open [Your jboss installation directory]/bin/run.conf.bat and add the javaagent flag to JAVA_OPTS at the end of the file:
set "JAVA_OPTS=%JAVA_OPTS% [generated javaagent flag]" |
- Leave ":JAVA_OPTS_SET
" as the last line in the file.
- Place the -javaagent
flag in one line (it cannot be split).
run.bat
script.Linux
Open [Your jboss installation directory]/bin/run.conf.bat
and add the javaagent
flag to JAVA_OPTS at the end of the file:
set "JAVA_OPTS=$JAVA_OPTS [generated javaagent flag]" |
- Place the -javaagent
flag in one line (it cannot be split).
run.sh
script.Open the script file:Windows
[Your weblogic installation directory]/user_projects/domains/[your domain]bin/startWebLogic.cmd |
Linux
[Your weblogic installation directory]/user_projects/domains/[your domain]bin/startWebLogic.sh |
Add the -javaagent
flag to JAVA_OPTIONS (in the section that starts with the START WEBLOGIC comment). The -javaagent
flag must be placed in a single line:
Windows
@REM START WEBLOGIC set JAVA_OPTIONS=%JAVA_OPTIONS% [generated javaagent flag] |
Linux
# START WEBLOGIC export JAVA_OPTIONS=$JAVA_OPTIONS [generated javaagent flag] |
Restart the server and open the following URL in the browser:
http://localhost:7001/Calculator |
The Jtest Agent will write runtime data according to the runtimeData
property of the -javaagen
t flag generated by the mvn package jtest:monitor
goal. By default, the runtime data be written to the [path to monitor dir]/monitor/runtime_coverage
directory.
Run the Calculate Application Coverage test configuration and pass the static_coverage.xml file and directory to the runtime coverage data using the dedicated -staticcoverage
and -runtimecoverage
parameters:
jtestcli -staticcoverage [path to static_coverage.xml file] -runtimecoverage [path/dir] -config "builtin://Calculate Application Coverage" |
The path to the static_coverage.xml file must point to the extracted contents of the monitor.zip package, which contains this file.
The path to the runtime_coverage directory is printed to the console as the runtimeData
property of the -javaagent
VM argument.