gpt4 book ai didi

android - Robolectric 测试未运行 (Android)

转载 作者:行者123 更新时间:2023-11-29 00:16:09 27 4
gpt4 key购买 nike

我已成功安装 Robolectric,但我的测试根本没有运行。没有错误,但也没有结果。我错过了什么?

运行./gradlew test 后没有测试报告,但是测试类生成正确

我的build.gradle:

buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
...
classpath 'io.fabric.tools:gradle:1.+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'idea'
apply plugin: 'hugo'
apply plugin: 'android'
apply plugin: 'robolectric'

idea {
module {
downloadJavadoc = true
downloadSources = true
testOutputDir = file('build/test-classes/debug')
}
}
repositories {
mavenCentral()
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
flatDir name: 'localRepository', dirs: 'libs-aar'
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
repositories {
mavenCentral()
}
...
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
useOldManifestMerger true
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
buildConfigField "String", "GIT_SHA", "\"${gitSha()}\""
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
// buildConfigField "String", "BUILD_TIME", buildTime()
}
...
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/com', 'src/se', 'src/viewpagerindicator' , 'src-gen']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
...
androidTest {
setRoot('src/androidTest')
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
...
robolectric {
include '**/*Tests.class'
exclude '**/espresso/**/*.class'
}

我的测试:

@RunWith(RobolectricTestRunner.class)
public class StartTest {
@Test
public void testSomething() throws Exception {
//Activity activity = Robolectric.buildActivity(DeckardActivity.class).create().get();
assertTrue(true);
}
}

最佳答案

我认为问题出在您的文件掩码上。您包含了 Tests.class,但您的类名为 StartTest(请注意缺少的 s),因此它不会被包含在内。

关于android - Robolectric 测试未运行 (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26774993/

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