Android:代码覆盖率的本地测试?
我想为我的类定义单元测试,并遇到以下问题。如果我在androidTest文件夹中定义了单元测试(使用工具测试),那么测试将正常运行,结果有效。但是,如果我在测试文件夹(本地测试)中定义了测试,那么运行测试会生成一条消息“class not found:”[classname]“Empty test suite”。这不会太糟糕,我会从androidTest运行所有测试,除了我想使用代码覆盖率,AndroidStudio不允许我从androidTest运行覆盖率测试,而只允许从test运行 为什么当单元测试在test文件夹中定义时,androidstudio无法找到它们,而当它们在androidTest文件夹中定义时,androidstudio却能够找到它们 代码: 渐变配置:Android:代码覆盖率的本地测试?,android,unit-testing,android-studio,android-testing,jacoco,Android,Unit Testing,Android Studio,Android Testing,Jacoco,我想为我的类定义单元测试,并遇到以下问题。如果我在androidTest文件夹中定义了单元测试(使用工具测试),那么测试将正常运行,结果有效。但是,如果我在测试文件夹(本地测试)中定义了测试,那么运行测试会生成一条消息“class not found:”[classname]“Empty test suite”。这不会太糟糕,我会从androidTest运行所有测试,除了我想使用代码覆盖率,AndroidStudio不允许我从androidTest运行覆盖率测试,而只允许从test运行 为什么当
android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
debug {
testCoverageEnabled = true
}
}
testCompile 'junit:junit:4.12'
testCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
这本身可能不是一个答案 你可以试着换衣服
testCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
到
在最近的gradle版本中,它似乎是默认的运行程序
后者对我有效,但前者无效
编辑:
经过一番挣扎之后,现在看来降级到2.2.3版是一个解决方案,smth必须在作者使用的2.3测试版中有所改变如何运行测试(失败)?您是否尝试在一个类/目录级别上运行?右键单击测试类-“run[testname]with coverage”在最新创建的项目中按预期工作,我们可以尝试查找差异您的gradle版本是什么?版本是:2.3.0-Beta1我尝试过替换它,但仍然失败“进程已完成,退出代码为1..Empty test suite”您的案例中的InstrumentationRegistry是什么?它应该在无设备设置中运行吗?我想运行Sqlite包装的测试,它需要一个上下文,因此需要instrumentationRegistry。我试着注释这句话,但是测试也以同样的方式失败了对不起,我不知道,你的构建工具版本是什么?你介意试试gradle:2.2.3吗?buildToolsVersion“25.0.2”-当然,我会试试。谢谢你的帮助:)
testCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})