您好我正在尝试使用Robolectric Test框架在我的Android应用程序上运行单元测试。
然而。当我运行命令./gradlew test时,它似乎根本不运行我的单元测试。
这是我得到的输出:
./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
这是我的测试类在运行测试时应该失败
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");
}
}
我的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()
}
}
答案 0 :(得分:1)
我想我破解了它。
我必须将我的测试用例文件夹从src / androidTest重命名为src / test