在新版本中添加这些:
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
我在导入某些Android UI测试框架类时遇到问题-我只是不知道出了什么问题!
这是我的课程:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ExampleUnitTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
@Test
public void listGoesOverTheFold() {
onView(withText("Hello world!")).check(matches(isDisplayed()));
}
}
但是由于某些原因,出现错误'找不到符号ActivityTestRule'和'找不到符号AndroidJUnit4'。我尝试导入它们,但是找不到它们。
build.gradle中的依赖项设置为:
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
所以我想我已经完成了所有依赖项设置-我已经尝试了很多事情,但是没有运气。
有人有什么想法吗?
您可以在Android中设置两种不同类型的测试
单元测试
test/java
包中>testCompile
将依赖项添加到build.gradle文件中>仪器测试
androidTest/java
包中>androidTestCompile
的build.gradle中添加依赖项>据我所知,您正在尝试使用Espresso编写仪器测试,但是将您的测试放在用于单元测试的test/java
包中。在这种情况下,您需要将测试类移至androidTest/java
包。
在新版本中添加这些:
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
如果您迁移到AndroidX,请使用此:
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
添加:
androidTestImplementation 'com.android.support.test:rules:1.0.2'
解决了问题,但不要忘记将项目与gradle文件同步。只有这样,更改才会生效。
需要此添加依赖项
testCompile 'com.android.support.test:rules:0.5'
testCompile 'com.android.support.test:runner:0.5'
添加依赖项。
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
在Android中编写UI测试
(((在Android设备/仿真器上运行的测试)),请确保测试类位于androidTest
请确保您在build.gradle中进行以下依赖
androidTestImplementation'androidx.test.espresso:espresso-core:3.2.0'androidTestImplementation'androidx.test:runner:1.2.0'androidTestImplementation'androidx.test:rules:1.2.0'androidTestImplementation'androidx.test.ext:junit:1.1.1'testImplementation'junit:junit:4.13'
对于单元测试
(确保在JVM上运行的测试)>1.Test类在test
包中2。确保在build.gradle中进行以下依赖
testImplementation 'junit:junit:4.13' testImplementation 'org.mockito:mockito-core:2.23.0'
从androidX使用
androidTestImplementation'androidx.test:rules:1.1.1'
androidTestImplementation'androidx.test:runner:1.1.1'
在应用程序级别build.gradle文件的依赖项部分
例如:
> dependencies { > > androidTestImplementation 'androidx.test:rules:1.1.1' > androidTestImplementation 'androidx.test:runner:1.1.1' > }
然后导入
import androidx.test.rule.ActivityTestRule;
在新版本中添加这些:
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
如果您迁移到AndroidX,请使用此:
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
添加:
androidTestImplementation 'com.android.support.test:rules:1.0.2'
解决了问题,但不要忘记将项目与gradle文件同步。只有这样,更改才会生效。
需要此添加依赖项
testCompile 'com.android.support.test:rules:0.5'
testCompile 'com.android.support.test:runner:0.5'
添加依赖项。
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
在Android中编写UI测试
(((在Android设备/仿真器上运行的测试)),请确保测试类位于androidTest
从androidX使用
androidTestImplementation'androidx.test:rules:1.1.1'
androidTestImplementation'androidx.test:runner:1.1.1'
在应用程序级别build.gradle文件的依赖项部分