- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试在新的 Android 项目中创建 Espresso UI 测试,但遇到了以下问题。
如果我尝试创建一个空的测试类:
import android.content.Intent;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
}
我总是收到此错误消息:
cannot resolve symbol AndroidJUnit4.class
而且几乎所有导入的库都被标记为未使用。
build.gradle 文件包含以下内容:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.some.thing.xxx"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.orhanobut:logger:1.11'
// App dependencies
compile 'com.android.support:support-annotations:23.0.0'
// TESTING DEPENDENCIES
androidTestCompile 'com.android.support.test:runner:0.3'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
// add this for intent mocking support
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
// add this for webview testing support
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
}
如果我将这些设置放在我的其他测试项目上它可以工作,所以我不知道会出现什么问题?
我已按照本教程进行操作:"
http://www.vogella.com/tutorials/AndroidTestingEspresso/article.html
我已经尝试通过以下 SO 问题来解决它: Cannot resolve symbol 'AndroidJUnit4'
但没有运气。
非常感谢您的任何建议。
最佳答案
我也尝试过 vogella 的相同教程,但遇到了很多问题。我遇到的第一个问题是 v23 库的注释版本和 Espresso 库之间的依赖冲突。
然后我找到了 Roger Hu 的另一个最近更新的教程“UI Testting with Espresso”。我注意到 Espresso 还不支持 Marshmallow 的说法。
依赖添加如下:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
这解决了我的依赖冲突,我没有看到任何其他问题发生。
关于Android Espresso : cannot resolve symbol AndroidJUnit4. 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175847/
我实际上正在尝试在使用以下类的 AndroidJunit 测试项目中实现一个简单的测试套件 用户界面对象 用户界面选择器 UiAutomator 测试用例 在 Android 设备上单击并打开 Mes
我在使用 jacoco 为 Android Instrumentation Test 创建测试报告时遇到问题。我正在使用 AndroidJUnit4 创建测试用例。 这是我正在做的: 创建测试用例并放
我是一名优秀的程序员,十分优秀!