Note This is a test suite generation tool for Kotlin Android projects.
运行根模块下的 fatJar
任务,build/libs/kotsuite-core-fat-xxx.jar
即为我们需要的 KotSuite Core Jar 包。
- Build
kotsuite-agent
module: it will generate thekotsuite-agent-shadow-1.x-all.jar
and put it inlibs/cli
- Build
kotsuite-kotmain
module: it will generate theKotMain.class
file and put it inlibs/cli
# 1. Generate .jar file
kotlinc -include-runtime -d output.jar ./Example.kt
# 2. Move and extract .jar file
cp \
./src/test/targets-resources/src/SimpleClass/output.jar \
./src/test/targets-resources/generated/
jar xf output.jar
# Logging options
gradlew build -i
# 1. Generate .jar file for target bytecodes
cd example-projects/MyApplication/sootOutput
jar -cvf ../kotsuite/MyApplication.jar *.class com/
# 2. Run the generated .jar file to validate
cd example-projects/MyApplication/sootOutput
java \
-cp "./example-projects/MyApplication/kotsuite/MyApplication.jar;./libs/kotlin-runtime-1.2.71.jar" \
ExampleTest
java \
-cp "./example-projects/MyApplication/sootOutput:./libs/kotlin-runtime-1.2.71.jar:./libs/kotlin-stdlib-1.8.10.jar" \
KotMain
# 3. Generate .exec file
java \
-javaagent:./libs/cli/org.jacoco.agent-0.8.10-runtime.jar=includes=*,destfile=./example-projects/MyApplication/sootOutput/report/jacoco-MyApplication.exec,output=file \
-cp ./example-projects/MyApplication/kotsuite/MyApplication.jar \
ExampleTest
# 4. Generate coverage report
java \
-jar ./libs/cli/org.jacoco.cli-0.8.10-nodeps.jar report \
./example-projects/MyApplication/sootOutput/report/jacoco-MyApplication.exec \
--classfile=./example-projects/MyApplication/sootOutput \
--sourcefile=./example-projects/MyApplication/app/src/main/java \
--html ./example-projects/MyApplication/sootOutput/report/HTML
- Generate test class file
- Run cmd command to package a jar file
- Generate .exec file
- Run cmd command to generate HTML report
About java decompiler (fernflower)
java -jar final/classes final/decompiled
java \
-cp "./build/libs/kotsuite-1.0-SNAPSHOT.jar;./libs/*" \
org.kotsuite.client.MainKt \
--project ".\example-projects\MyApplication" \
--includes "com.example.myapplication.Example&com.example.myapplication.Callee" \
--strategy "random" \
--libs "./libs/"
java \
-jar "./build/libs/kotsuite-1.0-SNAPSHOT.jar" \
--project ".\example-projects\MyApplication" \
--includes "com.example.myapplication.Example&com.example.myapplication.Callee" \
--strategy "random" \
--libs "./libs/"
Report
Statistic
- 新增:输出测试生成的结果统计
- 测试报告:
$MODULE_ROOT/kotsuite/$TIMESTAMP/final/report/report_xxx.json
- 测试数据统计
$MODULE_ROOT/kotsuite/$TIMESTAMP/final/report/statistic_xxx.json
- 测试报告:
- 新增:测试生成时的日志文件
- 日志文件:
$MODULE_ROOT/kotsuite.log
- 日志文件:
- 变更:测试生成时生成的中间文件和最终文件的路径
- 修改为
$MODULE_ROOT/kotsuite/$TIMESTAMP/
- 修改为
- 变更:最终输出的测试用例的筛选逻辑
- 由「根据覆盖率高低筛选」变为「选择覆盖信息不同的测试用例,去除覆盖信息完全相同的测试用例」
- 修复:classpath 过长导致无法创建 Java 进程的问题