问题描述
我用在我的项目的味道,我想添加特定的针对每种口味添加仪器测试。
I use flavors in my project and I wanna add add instrumentation tests specific for each flavor.
因此,我创建
MyApplication/src/androidTestFlavor1/java/com.package.test
MyApplication/src/androidTestFlavor2/java/com.package.test
不过,这并不正常工作。
But it doesn't work correctly.
所以,我试图将其配置在build.gradle,我已经添加了
So, I've tried to configure it in build.gradle, I've added
android {
...
sourceSets {
flavor1{
instrumentTest.setRoot('src/instrumentationTestFlavor/java')
}
}
...
}
但我得到的错误:
but I get error:
错误:(59,0)找不到属性instrumentTest源集丁
什么是最好的解决办法吗?
What's the best solution here?
推荐答案
当您安装在机器人工作室它创建一个主文件夹和文件夹androidTest一个新的项目。摇篮使用androidTest文件夹中所有的口味常见的测试。请参见链接。所以如果你打算尝试写一个味道特定的测试,并把它放在androidTest文件夹,它将会运行对所有的口味,并可能会失败。
When you setup a new project in android studio it creates a main folder and an androidTest folder. Gradle uses the androidTest folder for common tests across all flavors. See link. So if you try try to write a flavour specific test and put it in the androidTest folder, it will be run against all your flavors and will probably fail.
所以,如果你想创建特定的口味测试,你需要添加一个新的测试文件夹包含Java文件夹和测试的味道。命名约定必须androidTestFlavorName。见下图。
So if you want to create flavor specific tests you need to add a new test folder for that flavor containing the java folder and your test. The naming convention has to be androidTestFlavorName. See image below.
这篇关于香精和仪表测试 - 摇篮配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!