"Duplicate class io.mockk.ValueClassSupportKt found" when using in 1.12.0
See original GitHub issuePrerequisites
Please answer the following questions for yourself before submitting an issue.
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
Expected Behaviour
Android instrumented tests should run.
Current Behaviour
Android instrumented tests fail with Duplicate class io.mockk.ValueClassSupportKt found
compilation error (see stack trace below).
Failure Information (for bugs)
When upgrading from 1.11.0 to 1.12.0, tests no longer run. Seems to be affecting others that have commented on #653.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- Run tests successfully
- Upgrade Gradle dependencies to 1.12.0
- Tests fail
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- MockK version: 1.12.0
- OS: macOS 12
- Kotlin version: 1.53.1
- JDK version: 11
- JUnit version: 5
- Type of test: android instrumented test
Stack trace
> Task :app:checkDebugAndroidTestDuplicateClasses FAILED
Execution failed for task ':app:checkDebugAndroidTestDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class io.mockk.ValueClassSupportKt found in modules jetified-mockk-agent-android-1.12.0-runtime (io.mockk:mockk-agent-android:1.12.0) and jetified-mockk-agent-jvm-1.12.0 (io.mockk:mockk-agent-jvm:1.12.0)
Minimal reproducible code (the gist of this issue)
dependencies {
...
testImplementation "io.mockk:mockk:1.12.0"
testImplementation "io.mockk:mockk-agent-jvm:1.12.0"
...
androidTestImplementation "io.mockk:mockk-android:1.12.0"
androidTestImplementation "io.mockk:mockk-agent-jvm:1.12.0"
}
@Test
fun noPermission() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.has_permission))
.check(matches(withText("No permission.")))
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:5
Top Results From Across the Web
Android Kotlin Unit test failing with io.mockk.MockKException
In your setup() method, you're creating a viewmodel first and then configuring your mock reponse in the repository after.
Read more >MockK | mocking library for Kotlin
Provides DSL to mock behavior. Built from zero to fit Kotlin language. Supports named parameters, object mocks, coroutines and extension function mocking.
Read more >io.mockk : mockk : 1.12.0 - Maven Central Repository Search
MockK - mocking library for Kotlin.
Read more >Mockk for Java Mockito developers, an introduction - Medium
All the code in this blog post can be found in this Github repo. Getting started. The only requirement to use both testing...
Read more >MockK: A Mocking Library for Kotlin - Baeldung
Most JVM mock libraries have problems with mocking or stubbing final classes. Of course, we can add the “open” keyword to classes and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What worked for me was excluding the second module for the
androidTestImplementation
configuration:Any idea how to apply this to all the modules at once?
When I tried this in the top-level (root)
build.gradle.kts
:then it didn’t work. It looks like at this stage the
configurations
are not prepared yet so there is no way to findandroidTestImplementation
.The suggested workaround worked for me only when I added it in the module-specific
build.gradle.kts
file but I don’t want to add it to all of my modules because it’s really tedious and easy to forget about, not to mention updating this in the future if necessary.Do you really think this issue should be closed already? Is there no way for the
mockk
library to fix this problem?EDIT (Mar 24 14:44 UTC):
If anyone is interested, I figured out I can exclude
mockk-agent-jvm
from all the modules at once either by something like:or by extracting the common parts of the module’s setup from the
android { ... }
block from eachbuild.gradle.kts
intobuildSrc
and handling it there, for example something like: