New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix an issue that Android Instrumentation Test fails #895
Changes from all commits
f9a22af
f770509
d9bb509
47f470e
2e186ea
e364606
b64549f
eedb520
c18440f
244b334
3275c3b
afcfc2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ android { | |
defaultConfig { | ||
minSdk = 21 | ||
targetSdk = 32 | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
testOptions { | ||
execution = "ANDROIDX_TEST_ORCHESTRATOR" | ||
} | ||
|
||
compileOptions { | ||
|
@@ -44,6 +49,20 @@ android { | |
} | ||
} | ||
|
||
dependencies { | ||
testImplementation("junit:junit:${Deps.Versions.junit4}") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:${Deps.Versions.androidxEspresso}") { | ||
exclude("com.android.support:support-annotations") | ||
} | ||
|
||
androidTestImplementation("androidx.test:rules:${Deps.Versions.androidxTestRules}") | ||
androidTestImplementation("androidx.test:runner:${Deps.Versions.androidxTestRunner}") | ||
androidTestImplementation("androidx.test.ext:junit-ktx:${Deps.Versions.androidxTestExtJunit}") | ||
|
||
androidTestImplementation(kotlin("test")) | ||
androidTestImplementation(kotlin("test-junit")) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝I thought it would be better to make the test configs common, so I moved them here. |
||
val javadocJar by tasks.registering(Jar::class) { | ||
from(tasks.dokkaJavadoc) | ||
archiveClassifier.set("javadoc") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,40 +11,17 @@ description = "Mocking library for Kotlin (Android instrumented test)" | |
val mavenName: String by extra("MockK Android") | ||
val mavenDescription: String by extra("${project.description}") | ||
|
||
@Suppress("UnstableApiUsage") | ||
android { | ||
packagingOptions { | ||
resources { | ||
excludes += "META-INF/LICENSE.md" | ||
excludes += "META-INF/LICENSE-notice.md" | ||
} | ||
} | ||
|
||
defaultConfig { | ||
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" | ||
testInstrumentationRunnerArguments["notAnnotation"] = "io.mockk.test.SkipInstrumentedAndroidTest" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝This class was not included in the test APK and an error log was displayed, so I remove this |
||
} | ||
|
||
sourceSets { | ||
getByName("androidTest").assets.srcDirs("$projectDir/common/src/test/kotlin") | ||
} | ||
} | ||
|
||
dependencies { | ||
api(projects.modules.mockk) | ||
api(projects.modules.mockkAgentApi) | ||
api(projects.modules.mockkAgentAndroid) | ||
|
||
testImplementation("junit:junit:${Deps.Versions.junit4}") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:${Deps.Versions.androidxEspresso}") { | ||
exclude(group = "com.android.support", module = "support-annotations") | ||
} | ||
androidTestImplementation(kotlin("reflect")) | ||
|
||
androidTestImplementation("androidx.test:rules:${Deps.Versions.androidxTestRules}") | ||
|
||
androidTestImplementation(kotlin("test")) | ||
androidTestImplementation(kotlin("test-junit")) | ||
androidTestImplementation(Deps.Libs.junitJupiter) | ||
androidTestImplementation(Deps.Libs.junitVintageEngine) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
package io.mockk.proxy.android | ||
|
||
import android.widget.FrameLayout | ||
import androidx.test.rule.ActivityTestRule | ||
import io.mockk.debug.TestActivity | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.mockk.mockk | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class AndroidMockKAgentFactoryTest { | ||
|
||
@Rule | ||
@JvmField | ||
val rule = ActivityTestRule(TestActivity::class.java) | ||
Comment on lines
-12
to
-14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Removed because it's unnecessary. |
||
|
||
/** | ||
* This tests that the hidden api logic in [AndroidMockKAgentFactory] works. Otherwise, we would fail when mocking | ||
* the FrameLayout. | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Using Test Orchestrator makes Instrumentation Test stable. Documentation