相关疑难解决方法(0)

如何将Android支持存储库添加到Android Studio?

我正在使用Android Studio和外部Android SDK.我已经安装了支持库和支持库.支持存储库位于:

~/Development/Tools/android/sdk/extras/android/m2repository
Run Code Online (Sandbox Code Playgroud)

当我向build.gradle文件中的支持库添加依赖项时,例如:

...

repositories {
    mavenCentral()
}

...

dependencies {
   compile "com.android.support:support-v4:18.0.+"
}
Run Code Online (Sandbox Code Playgroud)

Android Studio找不到支持库(无法解析符号等),Gradle也找不到库:

Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
      > Could not find any version that matches com.android.support:support-v4:18.0.+.
        Required by:
            TestAndroidStudio:TestAndroidStudio:unspecified
Run Code Online (Sandbox Code Playgroud)

如何在Android Studio和/或build.gradle文件中指定Android支持存储库的位置?

android gradle android-support-library android-studio android-gradle-plugin

43
推荐指数
3
解决办法
11万
查看次数

java.lang.Exception:自定义运行器类AndroidJUnit4应该有一个带有签名AndroidJUnit4的公共构造函数(Class testClass)

gradle看起来像:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.google.developer.taskmaker"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-annotations:25.2.0'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:preference-v7:25.2.0'
    debugCompile 'im.dino:dbinspector:3.4.1@aar'
    // Android JUnit Runner
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    // Android runner and rules support

    // add this for …
Run Code Online (Sandbox Code Playgroud)

android android-espresso

21
推荐指数
3
解决办法
8187
查看次数

Android检测测试未发现任何测试

我是Android仪表单元测试的新手.我有一个看起来像这样的简单测试.这是仪器化测试; 在我真正编写一个实际的仪器测试之前,我只想测试一个简单的测试:

@RunWith(AndroidJUnit4.class)
@SmallTest
public class AddressBookKeepingInstrumentedTest {


    public static final String TEST_STRING = "This is a string";
    public static final long TEST_LONG = 12345678L;

    @Test
    public void test_simple() {
        assertEquals(2,1+1);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到以下错误:

junit.framework.AssertionFailedError: No tests found in com.example.myfirstapp.AddressBookKeepingInstrumentedTest
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1729)

Tests ran to completion.
Run Code Online (Sandbox Code Playgroud)

Gradle构建在此之前成功通过.任何想法为什么会这样?

android unit-testing android-instrumentation

10
推荐指数
2
解决办法
5843
查看次数

在Android studio中为单元测试配置测试文件夹

我在android studio项目中添加了一个单元测试文件夹.默认文件夹是andoidTest,但我在测试中添加了一个新文件夹和名称.(如robolectric样品测试)

当我在我的build.gradle中添加测试依赖项时,例如

testCompile("junit:junit:${junitVersion}")
testCompile ("org.robolectric:robolectric:${robolectricVersion}")
Run Code Online (Sandbox Code Playgroud)

它们不会被添加到项目下的外部库中,但是当我使用默认配置和使用时androidTestCompile,它可以添加外部库.

然后我想也许我应该在gradle中使用setRoot进行测试,所以我在build.gradle的android标签中使用了以下内容:

sourceSets {
        androidTest.setRoot('src/test')
}
Run Code Online (Sandbox Code Playgroud)

但仍然存在问题.我可以运行测试gradlew,但是测试文件夹中的类的导入不适用,也没有可见的外部库用于测试目的.

任何人都有解决此问题的方法吗?

android unit-testing gradle robolectric android-gradle-plugin

8
推荐指数
2
解决办法
8702
查看次数

空的测试套件.浓咖啡

我是自动化测试的新手.我想运行一个特定的测试类,即使我有测试套件,它也会输出为

"客户还没准备好......测试运行开始......测试完成了......空测试套件......"

我搜索过并发现了很多解决方案.但他们都没有为我工作.如果我能得到任何帮助,我将不胜感激.这是测试文件.

 package com.smsbits.veridoc.activity;

@RunWith(AndroidJUnit4.class)
public class TempActivityEspressoTest {
public Resources resources;

@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(TempActivity.class);

@Before
public void init() {
    resources = mActivityRule.getActivity().getResources();
}

@Test
public void testCheckInputs() {
    onView(withId(R.id.btnchange)).perform(click());
    onView(withId(R.id.tvrandom)).check(ViewAssertions.matches(withText("hello")));
}} 
Run Code Online (Sandbox Code Playgroud)

这是我的gradle文件.

android {  
... 
packagingOptions {
    ...
    exclude 'META-INF/XXX'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/DEPENDENCIES'
}

defaultConfig {
    ...
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

testOptions {
    unitTests.returnDefaultValues = true
}

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:23.0.1'
}

 }

dependencies{ …
Run Code Online (Sandbox Code Playgroud)

android ui-testing ui-automation junit-runner android-espresso

5
推荐指数
1
解决办法
440
查看次数

如何为Android运行单元测试不在设备或模拟器上?

在android子工作室的新子项目中,据我了解这种在设备或模拟器上运行的集成测试,检查应用程序的功能取决于SDK的android.但我确实有方法不依赖于android.他们的测试,我想花在JVM上,避免运行模拟器.

java continuous-integration android unit-testing jvm

4
推荐指数
1
解决办法
6624
查看次数

在Android Studio中将UnitTest转换为Instrumentation Test

因此,我从一个名为MyCoolObjectTest的UnitTest开始。需要进行一些测试测试,我通过拖动将类直接在Android项目视图中从test目录移动到androidTest目录。我的UnitTest过去工作正常;除了仪器部分。但是现在它根本不起作用。我不断

Class not found: "com.mypkg.MyCoolObjectTest"Empty test suite.
Run Code Online (Sandbox Code Playgroud)

我一直在整个stackOverflow和官方文档中寻找解决方案。到目前为止没有运气。有没有人经历过类似的事情?

(如果我将其拖回测试文件夹,它将正常工作;如果我将其重新拖动到androidTest文件夹,它将再次停止工作)

我记得那是设置受测试文件夹的一种方法。但是我不再记得了。

为了获得一些见识,我想在测试中使用一些android库,例如

public String stripFormatting(String input){
    return Html.fromHtml(input).toString();
}
Run Code Online (Sandbox Code Playgroud)

这就是为什么我需要仪器。

这是我的单元测试课程,其中包含一个测试示例:

@RunWith(AndroidJUnit4.class)
public class MyCoolObjectTest {
    @Test
    public void testJustToKnow() {
        String actual = "<b>0</b>";
        String expected = "0";
        assertThat(stripFormatting(actual), equalTo(expected));
    }
    public String stripFormatting(String input) {
        return Html.fromHtml(input).toString();
    }
}
Run Code Online (Sandbox Code Playgroud)

更新

这是我得到的另一条迹线。如果单击该方法而不是该类,则会得到以下跟踪:

刚才我单击了方法而不是整个类,并获得了以下跟踪信息:

11/04 13:51:16:启动testJustToKnow()$ adb push /Users/me/StudioProjects/Myapp/app/build/outputs/apk/app-debug.apk /data/local/tmp/com.mypkg.myapp $ adb shell pm install -r“ /data/local/tmp/com.mypkg.myapp” pkg:/data/local/tmp/com.mypkg.myapp成功

$ adb push /Users/me/StudioProjects/Myapp/app/build/outputs/apk/app-debug-androidTest-unaligned.apk /data/local/tmp/com.mypkg.Myapp.test $ adb …

android unit-testing android-studio android-instrumentation

4
推荐指数
1
解决办法
1150
查看次数

Android Espresso测试:未找到类:...空测试套件

我正在尝试将本示例中的内容-https://github.com/googlesamples/android-testing/tree/master/ui/espresso/BasicSample-实施到我的应用中。

当我尝试执行简单的Espresso测试时,会发生以下情况:

“ / Applications / Android Studio 2.2.3.app/Contents/jre/jdk/Contents/Home/bin/java”(...)

进程完成,退出代码为1找不到类:“ com.faces_shop.app.MainActivityTest”空测试套件。

(从Android Studio复制粘贴)

考试:

package com.faces_shop.app;

import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

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.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
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;

/**
 * Created by AnonymizedForReview on 2017-01-12.
 */
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {

    public static final String STRING_TO_BE_TYPED = "Espresso";

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    @Test
    public void …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio android-gradle-plugin android-espresso

2
推荐指数
1
解决办法
4327
查看次数