我见过类似问题的部分答案,但从来没有真正解决问题的答案。我已经把它简化为一个很小的应用程序来演示这个问题。
我使用的是最新版本的Android (V2.2.1),我安装了以下SDK:
1. Create new Android app using wizard
2. Updated build.gradle (app) per: [https://developer.android.com/training/testing/start/index.html#config-instrumented-tests](https://developer.android.com/training/testing/start/index.html#config-instrumented-tests) - Added under defaultConfig: - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- Added under dependencies - androidTestCompile 'com.android.support:support-annotations:23.0.1' <-- Changed to 23.4.0 to match newly generated app - androidTestCompile 'com.android.support.test:runner:0.4.1' - androidTestCompile 'com.android.support.test:rules:0.4.1'
1. Did project sync to sync Gradle
2. Under the "test" package add new test file - ExampleIntegrationTest.java (right next to ExampleUnitTest.java)
3. In the new file, created integration test per: [https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html](https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html)
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public interface ExampleIntegrationTest {
}这就是问题出现的地方--无法解决行上的符号AndroidJUnit4 :导入android.support.test.runner.AndroidJUnit4;
如果输入导入语句,则可以使用弹出建议:
- import android. - It shows "support as option"
- import android.support. - It shows "test" as an option
- import android.support.test. - Now it only shows "rule" as a option创建应用程序后,确保它使用的是“调试”变体
这个很干很干。据我所知,这应该是可行的,但出于某种原因,支持库并没有正确导入。
发布于 2016-06-02 17:00:56
通过将测试添加到
或者,在创建测试类时,通过在Project树的"Android“选项卡中选择新的类来添加测试
发布于 2017-04-28 16:52:27
请确保您的测试位于正确的文件夹。有些本地测试和检测测试必须驻留在各自的文件夹中,如下所示:
看一下这篇文章说..。
要运行您的仪器化测试,请执行以下步骤: 单击工具栏中的同步项目,确保项目与Gradle同步。以下列方式运行测试:若要运行单个测试,请打开“项目”窗口,然后右键单击“测试”,然后单击“运行”。若要测试类中的所有方法,请右键单击测试文件中的类或方法,然后单击“运行”。若要在目录中运行所有测试,请右键单击该目录并选择“运行测试”。Android Gradle插件编译位于默认目录(src/androidTest/java/)的仪器化测试代码,构建测试APK并生产APK,在连接的设备或模拟器上安装两个APK,并运行测试。然后,Android在Run窗口中显示测试执行的结果。
因此,对于插装测试,文件夹必须是(不要忘记情况)。
src/androidTest/java
对于本地测试,文件夹必须是
src/test/java
然后,您可以使用包文件夹来匹配您的应用程序包。
希望,这对社区有帮助!
https://stackoverflow.com/questions/37553155
复制相似问题