Android Studion 2.2.3Android。 @RunWith(AndroidJUnit4.class) - 無法在包中解析「androidTest」
安裝Android支持知識庫 - ver。 44.0.0
我的設置都在爲咖啡官方網站:
https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html
我嘗試在包androidTest寫儀器測試咖啡(Espresso)。
@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"
}
所以我在文件夾中的src/androidTest/JAVA/COM/myCompany中/
我StringUtilAndroidTest代碼創建StringUtilAndroidTest我的依賴關係:
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;' – Bill
import org.junit.runner.RunWith; - 無法解析符號'RunWith' – Alexei