gpt4 book ai didi

java - 导入中无法识别 AndroidTestCompile 依赖项

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:04 26 4
gpt4 key购买 nike

实际上,我的项目有单元测试。都配置在/src/test/java/ 最近需要在/src/androidTest/java添加插桩测试。为此,我在 build.gradle 中添加了 espresso 依赖项。

dependencies {
compile files('libs/pixlui-1-0-5.jar')
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar') {
transitive = true
}
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services-maps:7.3.0'
compile 'com.google.android.gms:play-services-location:7.3.0'
compile 'com.google.android.gms:play-services-gcm:7.3.0'

compile 'com.loopj.android:android-async-http:1.4.5'
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:20.+'
compile 'ch.acra:acra:4.5.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'com.squareup.picasso:picasso:2.3.4'
provided 'com.squareup.dagger:dagger-compiler:1.2.+'
compile 'com.squareup.dagger:dagger:1.2.+'
compile 'com.google.guava:guava:15.0'
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
compile 'com.mixpanel.android:mixpanel-android:4.5.3'
compile 'com.google.maps.android:android-maps-utils:0.3+'

// Testing dependencies
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude module: 'support-annotations'
}
}

之后我选择了 Build Variants -> Test Artifact -> Android Instrumentation Tests。

但是当我开始编写代码时,没有识别出任何依赖项:

“无法解析符号 onView”、“无法解析符号 ViewInteraction”等...

这是我的 Activity 测试:

import android.support.test.espresso.Espresso.onView;
import android.test.ActivityInstrumentationTestCase2;

import com.wiffinity.easyaccess.R;

/**
* Created by Javier on 05/06/2015.
*/
public class EntryActivityTest extends ActivityInstrumentationTestCase2<EntryActivity> {

public EntryActivityTest() {
super(EntryActivity.class);
}

@Override
protected void setUp() throws Exception
{
super.setUp();
getActivity();
}

public void testLoginButtonClicked(){
onView();

ViewInteraction entryBtn;
entryBtn = onView(withId(R.id.entry_button));

entryBtn.performClick();
}
}

为什么Android Studio 1.2 不能解决这些依赖?我忘记配置什么了吗?

最佳答案

您可能需要重建项目。

在 Android Studio 中:

构建 -> 重建项目。

如果它不能帮助运行以下 gradle 任务(假设您有一个包装器并且您的模块名称是“app”):

./gradlew app:dependencies

并确保您的 androidTest 任务包含 espresso 依赖项。

更新:

有时重建项目并不能解决问题,唯一的解决办法是通过执行 gradle assembleAndroidTest 任务手动重建测试 apk。

关于java - 导入中无法识别 AndroidTestCompile 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30665135/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com