Closed bohsen closed 5 years ago
can you post your complete build.gradle, or a zip/link to a sample project that can repro the issue?
Also, FWIW, alpha03 is available now too
https://github.com/android/android-test/releases/tag/androidx-test-1.2.0-alpha03
It's the same with newest alpha03 release
My buildfile:
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
classpath 'io.fabric.tools:gradle:1.28.1'
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
}
}
plugins {
id 'com.gladed.androidgitversion' version '0.4.9'
id "com.github.spotbugs" version "1.6.9"
id "com.vanniktech.android.junit.jacoco" version "0.13.0"
}
project.extensions.extraProperties.set('SpotBugsTask', com.github.spotbugs.SpotBugsTask)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'io.fabric'
apply plugin: 'spoon'
apply from: '../app/checkstyle.gradle'
apply from: '../app/ktlint.gradle'
apply from: '../app/androidgit.gradle'
apply from: '../app/spotbugs.gradle'
androidExtensions.experimental = true
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example"
minSdkVersion 22
targetSdkVersion 28
versionName androidGitVersion.name()
versionCode androidGitVersion.code()
testInstrumentationRunner "com.example.utils.CustomJUnit4TestRunner"
multiDexEnabled false
dataBinding.enabled = true
// Upon compilation, export our Room database schema into a JSON file. These represent
// our database's schema history and are used for database migrationtesting
// used by Room, to test migrations
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString(),
"androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString()
// You can set optional Android Annotation processing options here, like these commented options:
// "logLevel": 'INFO',
// "logFile": "$buildDir/generated/source/kapt/androidannotations.log".toString()
]
}
}
javaCompileOptions {
annotationProcessorOptions {
compilerArgumentProvider new EnableDaggerIncrementalAP()
}
}
testInstrumentationRunnerArguments clearPackageData: 'true'
}
buildTypes {
debug {
testCoverageEnabled true
ext.enableCrashlytics = false
}
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
def commonTestDir = 'src/commonTest/java'
test {
java.srcDirs += commonTestDir
resources.srcDirs += ['src/commonTest/resources']
}
androidTest {
java.srcDirs += commonTestDir
resources.srcDirs += ['src/commonTest/resources']
}
// Adding the Room database schema location as an asset folder for testing purposes. This
// allows Room to create older versions of our database
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
testOptions {
// execution 'ANDROIDX_TEST_ORCHESTRATOR'
animationsDisabled true
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
tasks.withType(Test).configureEach {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen { false }
showStandardStreams = true
showCauses true
showStackTraces true
// set options for log level DEBUG and INFO
debug {
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full"
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Dependencies for Android Core Components:
implementation "com.google.android.material:material:$material_components_version"
implementation "androidx.recyclerview:recyclerview:$androidx_recyclerview_version"
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidx_coordinatorlayout_version"
implementation "androidx.activity:activity-ktx:$androidx_activity_version"
implementation "androidx.fragment:fragment-ktx:$androidx_fragment_version"
implementation "androidx.fragment:fragment-testing:$androidx_fragment_version"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayout_version"
implementation "androidx.core:core-ktx:$androidx_core_version"
implementation "androidx.preference:preference-ktx:$androidx_preference_version"
// Dependencies for kotlin:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_coroutines_version"
implementation "ru.gildor.coroutines:kotlin-coroutines-retrofit:$kotlin_retrofit_coroutines_version"
// Dependencies for Android Architecture Components: Lifecycle, LiveData, and ViewModel
implementation "androidx.lifecycle:lifecycle-extensions:$androidx_lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$androidx_lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$androidx_lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$androidx_lifecycle_version"
// Test helpers for LiveData
testImplementation "androidx.arch.core:core-testing:$architecture_components_lifecycle_version"
androidTestImplementation "androidx.arch.core:core-testing:$architecture_components_lifecycle_version"
// Dependencies for Android Architecture Components: Room SQLite database framework
implementation "androidx.room:room-runtime:$architecture_components_room_version"
kapt "androidx.room:room-compiler:$architecture_components_room_compiler_version"
implementation "androidx.sqlite:sqlite-ktx:$sqlite_ktx_version"
// optional - Coroutines support for Room
implementation "androidx.room:room-ktx:$architecture_components_room_version"
// Test helpers for Room
testImplementation "androidx.room:room-testing:$architecture_components_room_version"
androidTestImplementation "androidx.room:room-testing:$architecture_components_room_version"
// Dependencies for Dagger2 Core dependency injection framework
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
// Dependencies for Retrofit REST framework
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
// Dependencies for OkHttp networking framework
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
// MockWebserver
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
// Dependencies for Timber logging framework
implementation "com.jakewharton.timber:timber:$timber_version"
// Dependencies for GSON Json serializer
implementation "com.google.code.gson:gson:$gson_version"
// Dependencies for LeakCanary (Memory Leak detection library)
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanary_version"
androidTestImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanary_version"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanary_version"
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanary_version"
// Dependencies for JUnit
testImplementation "junit:junit:$junit_version"
// Dependencies for Mockito
// For local unit tests on your development machine
testImplementation "org.mockito:mockito-core:$mockito_version"
testImplementation "org.mockito:mockito-inline:$mockito_version"
androidTestImplementation "org.mockito:mockito-core:$mockito_version"
androidTestImplementation "org.mockito:mockito-android:$mockito_version"
// Dependencies for Mockito-Kotlin
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlin_version"
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlin_version"
// Dependencies for Retrofit Mock
testImplementation "com.squareup.retrofit2:retrofit-mock:$retrofit_version"
androidTestImplementation "com.squareup.retrofit2:retrofit-mock:$retrofit_version"
// Dependencies for TestButler
androidTestImplementation "com.linkedin.testbutler:test-butler-library:$testButler_version"
// Installs Testbutler test helper APK before instrumentation tests are run
androidTestUtil "com.linkedin.testbutler:test-butler-app:$testButler_version@apk"
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation "androidx.test:runner:$androidx_test_runner_version"
androidTestImplementation "androidx.test:rules:$androidx_test_rules_version"
androidTestImplementation "androidx.test:monitor:$androidx_test_monitor_version"
androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_test_ext_junit_version"
androidTestImplementation "androidx.test:core-ktx:$androidx_test_ext_core_version"
androidTestUtil "androidx.test:orchestrator:$androidx_test_orchestrator_version"
//Dependencies for Espresso
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
// Espresso intents for checking launched intents
androidTestImplementation "androidx.test.espresso:espresso-intents:$espresso_version"
// Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
androidTestImplementation("androidx.test.espresso:espresso-contrib:$espresso_version")
// Conditionwatcher for synchronization with background jobs (used instead of Espresso-idling-ressource)
androidTestImplementation "com.azimolabs.conditionwatcher:conditionwatcher:$conditionwatcher_version"
// DaggerMock for overriding an object managed by Dagger 2 with a mock
testImplementation "com.github.fabioCollini:DaggerMock:$daggerMock_version"
androidTestImplementation "com.github.fabioCollini:DaggerMock:$daggerMock_version"
androidTestImplementation "com.github.fabioCollini.daggermock:daggermock-kotlin:$daggerMock_version"
// Spoon testexecution, testreporting and reporting tool
androidTestImplementation "com.squareup.spoon:spoon-client:$spoon_version"
// Android annotation dependencies
kapt "org.androidannotations:androidannotations:$androidAnnotations_version"
implementation "org.androidannotations:androidannotations-api:$androidAnnotations_version"
// Crashlytics dependencies
implementation("com.crashlytics.sdk.android:crashlytics:$crashlytics_version@aar") {
transitive = true
}
// FloatingActionButton
implementation "com.github.conhea:floatingactionbutton:$floatingactionbutton_version"
}
spoon {
debug = true
}
class EnableDaggerIncrementalAP implements CommandLineArgumentProvider {
@Override
Iterable<String> asArguments() {
return ["-Adagger.gradle.incremental"]
}
}
And the dependencies:
gradle_version = '3.4.0-rc03'
// Runtime dependencies
androidx_version = '1.0.0'
androidx_core_version = '1.1.0-alpha05'
androidx_activity_version = '1.0.0-alpha06'
androidx_fragment_version = '1.1.0-alpha06'
androidx_recyclerview_version = '1.1.0-alpha04'
androidx_coordinatorlayout_version = '1.1.0-alpha01'
androidx_lifecycle_version = '2.1.0-alpha04'
androidx_preference_version = '1.1.0-alpha04'
architecture_components_lifecycle_version = '2.0.1'
architecture_components_room_version = '2.1.0-alpha06'
architecture_components_room_compiler_version = '2.1.0-alpha06'
sqlite_ktx_version = '2.0.1'
constraintLayout_version = '2.0.0-alpha2'
dataBindingCompiler_version = gradle_version // Always need to be the same.
material_components_version = '1.1.0-alpha05'
kotlin_version = '1.3.21'
kotlinx_coroutines_version = '1.1.1'
kotlin_retrofit_coroutines_version = '1.0.0'
dokka_version = '0.9.18'
gson_version = '2.8.5'
retrofit_version = '2.5.0'
okhttp_version = '3.14.0'
dagger_version = '2.22.1'
timber_version = '4.7.1'
androidAnnotations_version = '4.6.0'
floatingactionbutton_version = '2.0.2'
// Testdependencies
junit_version = '4.12'
espresso_version = '3.2.0-alpha03'
androidx_test_runner_version = '1.2.0-alpha03'
androidx_test_rules_version = '1.2.0-alpha03'
androidx_test_monitor_version = '1.2.0-alpha03'
androidx_test_orchestrator_version = '1.2.0-alpha03'
androidx_test_ext_core_version = '1.2.0-alpha03'
androidx_test_ext_junit_version = '1.1.1-alpha03'
mockito_version = '2.25.1'
mockitoKotlin_version = '2.1.0'
spoon_version = '1.7.1'
testButler_version = '1.3.2'
conditionwatcher_version = '0.2'
daggerMock_version = '0.8.4'
// Error reporting
crashlytics_version = '2.9.9'
leakCanary_version = '1.6.3'
// Static analysis tools
spotbugs_version = '3.1.11'
ktlint_version = '0.31.0'
checkstyle_version = '8.16'
Just found the cause. It's this dependency:
implementation "androidx.fragment:fragment-testing:$androidx_fragment_version"
Removing it removes the error.
Does fragment-testing need to be an implementation dependency as opposed to a androidTestImplementation?
If it does, does explicitly listing i implementation "androidx.test:core:1.2.0-alpha03" workaround the problem?
No, you're right. And changing it to androidTestImplementation
fixes the issue. Thanks for the help.
Does fragment-testing need to be an implementation dependency as opposed to a androidTestImplementation?
If it does, does explicitly listing i implementation "androidx.test:core:1.2.0-alpha03" workaround the problem? worked for me , thanks
Is there a reason why the docs at https://developer.android.com/training/basics/fragments/testing say to make fragment-testing a debug dependency?
If you are running Robolectric tests you would need it to be debugImplementation
Could you please explain why or link me to some more info?
Found and easy an convenient solution:
implementation ("androidx.fragment:fragment-testing:1.1.0-beta01",
exclude group: 'androidx.test', module: 'core'
})
Just found the cause. It's this dependency:
implementation "androidx.fragment:fragment-testing:$androidx_fragment_version"
Removing it removes the error.
But removing this doesnt allow us to use the feature "launchFragmentInContainer", Is there any workaround?
FWIW i followed the tutorial on fragment testing and got a bit confused about this. I now have the following in my dependencies...
debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion" <- This is what the tutorial tells you to do
testImplementation "androidx.fragment:fragment-testing:$fragmentVersion" <- This is needed to be able to compile the release variant of the unit test task - but it gives a big red warning saying 'Replace with debugImplementation`
My SO question that no one has answer (yet)
Shouldn't there be some sort of releaseImplementation package that contains the methods, but they're all stubs?
Is there a reason why the docs at https://developer.android.com/training/basics/fragments/testing say to make fragment-testing a debug dependency?
@davkutalek fragment-testing
has a stub activity that it uses to launchFragmentInContainer
. This activity needs to be present in the application's manifest for it to work and debugImplementation
is a way to inject it. That's the only explanation I could find and there maybe more to it.
Edit: See EmptyFragmentActivity
class in FragmentScenario
.
Description
When adding the newest alpha releases to my project I encounter the below error, when trying to execute tests from
androidTest
directory:Here are the dependencies I'm using:
Falling back on the stable versions removes the error:
This issue was originally posted on the googlesamples project
@brettchabot
No, not to my knowledge. Also why is this problem only present in the alpha release and not the newest stable release?
Steps to Reproduce
Example:
DatabaseTestRule (if relevant):
Expected Results
The test executes
Actual Results
The following error occurs:
AndroidX Test and Android OS Versions
Btw. It's the same with newest alpha03 release
Emulator running:
Link to a public git repo demonstrating the problem:
NA