This repository contains code for the following research tools:
- pankti: Tests from production data (documentation)
- rick: Tests + mocks from production data (documentation)
Head to the
Wiki for detailed tutorials!
Pankti transforms production workloads into test cases. The test generation pipeline consists of four phases:
- Extract
- Instrument
- Execute
- Generate
If you use this code for academic research, please cite: "Production Monitoring to Improve Test Suites", In IEEE Transactions on Reliability, 2021.
@article{arXiv-2012.01198,
title = {Production Monitoring to Improve Test Suites},
journal = {IEEE Transactions on Reliability},
year = {2021},
doi = {10.1109/TR.2021.3101318},
author = {Deepika Tiwari and Long Zhang and Martin Monperrus and Benoit Baudry},
}
pankti-extract leverages Spoon to statically analyze Java applications in order to find relevant methods for test generation. The output is a list of methods that meet the following criteria:
- they are public
- they are not empty
- they are not abstract, and do not belong to an interface or annotation type
- they are not deprecated and do not belong to a deprecated class
- they are not static
To run pankti-extract,
- Clone this repository
cd /path/to/pankti/pankti-extract/
mvn clean install
java -jar target/pankti-extract-<version>-jar-with-dependencies.jar /path/to/maven/project
- Available flags:
-h
(--help
) for usage,-v
(--void
) to include methods that return void
- The output is a CSV file at
/path/to/pankti/pankti-extract/
called extracted-methods-<project-name>.csv. - Generate Descartes report(s) to find pseudo-tested methods in the project (we use the
method.json
files)
python find-pseudo-tested.py /path/to/method/list/from/step5.csv /space/separated/paths/to/descartes/method.json
outputs a CSV with the list of methods that are candidates for instrumentation.
pankti-instrument is a Glowroot (download) plugin that serializes objects for instrumented methods that are invoked. pankti-instrument uses the Plugin API of Glowroot to instrument the methods extracted from pankti-extract.
To run pankti-instrument,
cd /path/to/pankti/pankti-instrument/
python instrument.py <path/to/instrumentation/candidates/from/previous/phase>.csv
- New aspect classes for these methods are generated in
se.kth.castor.pankti.instrument.plugins
. These aspect classes are also included in./src/main/resources/META-INF/glowroot.plugin.json
mvn clean install
- Drop
<pankti-instrument-<version>-jar-with-dependencies.jar
to/path/to/glowroot/plugins/
Execute the application with a workload, using Glowroot as a javaagent.
java -javaagent:/path/to/glowroot/glowroot.jar -jar <project-jar>.jar <cli-args>
The serialized objects for invoked methods are saved at /tmp/pankti-object-data/
.
Additionally, a list of invoked methods is generated at /tmp/pankti-object-data/invoked-methods.csv
.
pankti-generate creates test classes for an application from the collected object profiles.
It takes as input the path to the Java + Maven project, a CSV file with a list of invoked methods, and the path to the directory containing objects serialized as XML.
To run pankti-generate,
cd /path/to/pankti/pankti-generate/
mvn clean install
java -jar target/pankti-generate-<version>-jar-with-dependencies.jar /path/to/project /path/to/invoked/methods.csv /path/to/directory/with/objects/
The output is in a directory at /path/to/pankti/pankti-generate/output/generated/<project-name>/
. Generated test classes are placed in appropriate package directories. The naming convention followed is Test<ClassName>PanktiGen.java. Resource files for long XML strings are created at /path/to/pankti/pankti-generate/output/generated/object-data
.
🔭 Results and data: pankti-experiments
Rick transforms production workloads into tests that use mocks. In addition to some functionalities and implementation shared with pankti, it supports the instrumentation of methods that can be mocked within a test. It also handles the generation of these mocks with data collected from production.
- Clone this repository
cd pankti/
mvn clean install
To extract methods under test (MUTs) and mockable methods:
cd pankti/pankti-extract/
java -jar target/pankti-extract-<version>-jar-with-dependencies.jar /path/to/maven/project
- The output is
./extracted-methods-<project>.csv
To instrument MUTs and mockable methods:
cd pankti/pankti-instrument/
- Instrument all MUTs found across all classes:
python3 instrument-mock.py ../pankti-extract/extracted-methods-<project>.csv
- Alternatively, instrument MUTs found in a specific class under test (CUT):
python3 instrument-mock.py ../pankti-extract/extracted-methods-<project>.csv fully.qualified.name.of.CUT
- This generates aspect classes for MUTs and corresponding mockable methods in
se.kth.castor.pankti.instrument.plugins
- It also updates
./src/main/resources/META-INF/glowroot.plugin.json
mvn clean install
- Drop
<pankti-instrument-<version>-jar-with-dependencies.jar
to/path/to/glowroot/plugins/
To execute the target project:
java -javaagent:/path/to/glowroot/glowroot.jar <project-jar-and-options>
- The collected objects are stored at
/tmp/pankti-object-data/
- A CSV with the list of invoked MUTs is at
/tmp/pankti-object-data/invoked-methods.csv
- The collected objects are stored at
To generate tests:
cd pankti/rick/
java -jar target/rick-<version>-jar-with-depdendencies.jar /path/to/maven/project/ /tmp/pankti-object-data/invoked-methods.csv /tmp/pankti-object-data/
- The generated tests (
Test*PanktiGen.java
) are at./output/generated/<project>
- The generated tests (