我开始为我的公司实施仪器测试,以提高我们的代码质量和部署速度。我正在重写应用程序的一个模块,并尝试实施 TDD 原则。我的代码目前无法运行,因此我想将调试器附加到我的仪器测试中以验证其执行情况。除了在每次调试编译时我都会遇到错误Test run failed to complete. Instrumentation run failed due to Process crashed。
通过二分法,我创建了一个仅包含一个模块的简单项目,并启动了作为示例给出的仪器测试。
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.mylibrary.test", appContext.packageName)
}
}
Run Code Online (Sandbox Code Playgroud)
相同的结果。然后我在应用程序模块中启动了相同的仪器测试,令人惊讶的是,调试器已连接并触发了断点。
无法将调试器附加到模块中的仪器测试中?当我运行测试时,该测试有效并得到验证
您将在这里找到我的库的 build.gradle 文件
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.mylibrary'
compileSdk 33
defaultConfig {
minSdk 24
targetSdk …Run Code Online (Sandbox Code Playgroud)