简体   繁体   English

Android Gradle未运行单元测试

[英]android gradle not running unit test

Hi i am trying to use and run unit tests on my android app using the Robolectric Test framework. 嗨,我正在尝试使用Robolectric测试框架在我的android应用程序上使用和运行单元测试。

However. 然而。 when i run the command ./gradlew test it does not seem to run my unit tests at all. 当我运行命令./gradlew test时,它似乎根本没有运行我的单元测试。

here is the output i get: 这是我得到的输出:

./gradlew test
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugAndroidTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for debugAndroidTest as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareComSothreeSlidinguppanelLibrary300Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
/Users/jonathan/Work/CameraApp/app/src/main/res/drawable-mdpi/ic_drawer.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

/Users/jonathan/Work/CameraApp/app/src/main/res/drawable-hdpi/ic_drawer.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

/Users/jonathan/Work/CameraApp/app/src/main/res/drawable-xhdpi/ic_drawer.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:preCompileDebugUnitTestJava
:app:compileDebugUnitTestJava UP-TO-DATE
:app:compileDebugUnitTestSources UP-TO-DATE
:app:mockableAndroidJar
:app:assembleDebugUnitTest
:app:testDebug
:app:checkReleaseManifest
:app:prepareReleaseDependencies
:app:compileReleaseAidl
:app:compileReleaseRenderscript
:app:generateReleaseBuildConfig
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets
:app:generateReleaseResValues
:app:generateReleaseResources
:app:mergeReleaseResources
/Users/jonathan/Work/CameraApp/app/src/main/res/drawable-mdpi/ic_drawer.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

/Users/jonathan/Work/CameraApp/app/src/main/res/drawable-xhdpi/ic_drawer.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

/Users/jonathan/Work/CameraApp/app/src/main/res/drawable-hdpi/ic_drawer.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
:app:compileReleaseJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:preCompileReleaseUnitTestJava
:app:compileReleaseUnitTestJava UP-TO-DATE
:app:compileReleaseUnitTestSources UP-TO-DATE
:app:assembleReleaseUnitTest
:app:testRelease
:app:test

BUILD SUCCESSFUL

Total time: 9.009 secs

Here is my test class that should fail when running the test 这是我的测试类,在运行测试时应该会失败

package com.jonney.cameraapp;

import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static junit.framework.Assert.fail;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
@Config(emulateSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class ApplicationTest {

    @Test
    public void testSomething() {
        fail("testing fail state");
    }
}

My gradle script: 我的gradle脚本:

apply plugin: 'com.android.application'
apply plugin: 'org.robolectric'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.jonney.cameraapp"
        minSdkVersion 21
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.code.gson:gson:2.3'
    compile "joda-time:joda-time:2.4"
    androidTestCompile('junit:junit:4.12') {
        exclude module: 'hamcrest'
        exclude module: 'hamcrest-core'
    }
    androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
    androidTestCompile('org.mockito:mockito-core:1.9.5') {
        exclude module: 'hamcrest'
        exclude module: 'hamcrest-core'
    }
    compile 'com.sothree.slidinguppanel:library:3.0.0'

    compile 'com.jakewharton:butterknife:6.1.0'

    androidTestCompile('org.robolectric:robolectric:2.4') {

    }

    compile 'com.fasterxml.jackson:jackson-parent:2.5'
}


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.+'
        classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

I think i cracked it. 我想我破解了。

I had to rename my test case folder from src/androidTest to src/test 我不得不将测试用例文件夹从src / androidTest重命名为src / test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM