记录
Kotlin 测试生成进展记录¶
Java to Kotlin Converter¶
进展:
- 可以使用 Idea 插件的形式调用 ConvertJavaToKotlin Action,已经完成了 demo(IdeaProjects/j2k-plugin);
- 参考插件项目:Repos/multi-file-kotlin-converter-plugin, Repos/vcs-kotlin-converter, workspace/evosuite;
- 参考 Soot 项目:Repos/ERCatcher
TODO LIST:
- 写一个插件项目 demo,实现 Java to Kotlin
- 学习 idea 插件的开发
- 搭建整体架构
架构:
graph LR
A(Android APK) --Soot--> B(Jimple)
B --测试生成--> C(Bytecode测试用例)
C --Fernflower--> D(Java测试用例)
D --J2K--> E(Kotlin测试用例)
整体架构由两部分构成:
- 核心算法部分:
- 使用 Soot 分析 Android APK 得到 Jimple
- 在 Jimple 上生成 Bytecode 形式的测试用例
- 使用 Fernflower 将 Bytecode 反编译为 Java
- idea 插件部分:
- 获取待分析的 Android APK,启动核心算法
- 将生成的 Java 测试用例转化为 Kotlin
Android Studio Version¶
Android Studio Chipmunk | 2021.2.1 Patch 1
Build #AI-212.5712.43.2112.8609683, built on May 19, 2022
Runtime version: 11.0.12+7-b1504.28-7817840 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 8
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: CheckStyle-IDEA (5.67.4), org.jetbrains.kotlin (212-1.7.0-release-281-AS5457.46)
对应 IntelliJ IDEA Version:2021.2.4
IntelliJ Platform Plugin SDK¶
PART I - Plugins¶
Plugin Structure¶
- Manage State: Magage some state or logic that is only needed when the user performs a specific operation -> Service
- Persisting State: Store the state of your plugin at the application or project level -> Service (PersistentStateComponent interface, Persisting State of Components)
- SubScribing to Events: Subcribe to events -> listener | create an extension for a dedicated extension point
- Application Startup -> listener (subsribing to the
AppLiftcycleListenertopic)
Other¶
- Android Studio Plugin Development
- Tools - Gradle IntelliJ Plugin
- 将运行插件后启动的 Android Studio 示例运行在 JBR 上
- Gradle IntelliJ Plugin - Usage Examples
- IntelliJ Platform Explorer: A search tool for browsing Extension Points, Services and Listeners
- Explore the IntelliJ PlatformAPI
- Gerrit Code Review: 一个 IntelliJ Plugin 例子
- EvoSuite 插件修改版
Part II - Base Platform¶
¶
架构设计¶
graph LR
A(Idea 插件) --"选择参数、命令行调用"--> B(jar 包)
graph LR
A(程序分析) --"选择参数、命令行调用"--> B(测试生成)
- Idea 插件
- Java -> Kotlin
- 界面化(运行、参数设置、运行输出)
- 自动设置 project 和 module 路径
- jar 包
- 代码逻辑
- 生成算法
UI 设计¶
- 添加右键 popmenu -> Run KotSuite
- 添加底部 toolWindow -> 显示 KotSuite 运行日志
- 添加 Dialog -> 显示运行选项
未来工作¶
- 学习 IntelliJ Plugin 开发,阅读文档;
- 看 EvoSuite 源码,学习插件 + jar 包的项目架构;
- 看 Gerrit 插件源码;
Reference Projects¶
- IdeaProjects/evosuite -> 插件和 jar 包的组合方式(主要参考项目)
- IdeaProjects/gerrit-intellij-plugin -> 插件和 jar 包的组合方式
- Repos/intellij-community -> intellij platform 开源平台
- IdeaProjects/kotsuite -> 框架项目
- IdeaProjects/intellij-sdk-code-samples -> 插件官方样例
- https://github.com/GZoltar/gzoltar -> Java 项目架构
数据集¶
- DroidBench
- Github/testing-sample: A collection of samples demonstrating different frameworks and techniques for automated testing
AndroidTest¶
Developing Android unit and instrumentation tests - Tutorial
app/src/main/kotlin- for your source code of your main application buildapp/src/test/kotlin- for any unit test which can run on the JVMapp/src/androidTest/kotlin- for any test which should run on an Android device






