【发布时间】:2017-02-22 17:10:32
【问题描述】:
Android Studio 2.2.3
安装 Android 支持存储库 - 版本。 44.0.0
我在 Espresso 的官方网站上进行了所有设置:
https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html
我尝试在 androidTest 包中编写仪器测试 (Espresso)。所以我在文件夹 src/androidTest/java/com/mycompany/
中创建 StringUtilAndroidTest我的 StringUtilAndroidTest 代码:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class StringUtilAndroidTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
@Test
public void myTest() {
assert(true);
}
}
在我的 build.gradle 中:
android.defaultconfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
我的依赖:
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1
但在 StringUtilAndroidTest 中出现编译错误:
@RunWith(AndroidJUnit4.class)
无法解析符号 RunWith
为什么?
【问题讨论】:
-
除了将 androidTestCompile 行添加到您的 build.gradle 之外,您还记得在 Java 文件的顶部导入类吗?即
import org.junit.runner.RunWith; -
导入 org.junit.runner.RunWith; - 无法解析符号“RunWith”
标签: android unit-testing