How to setup Mockk for an Android project - gradle

I added the mock dependecy to the build.gradle:
testImplementation "io.mockk:mockk:1.13.2"
testImplementation "io.mockk:mockk-agent-jvm:1.13.2"
Now I want to use the import:
io.mockk.*
This dosen't work and android studio says:
Unresolved reference: mockk

The problem was that i was in the androidTest and not the test[UnitTest] folder.

Related

Getting a "cannot find proxyClass" when using vertx's WebApiServiceGen

I'm following this example https://github.com/vert-x3/vertx-examples/tree/master/web-api-service-example. Instead of using Java and Maven I'm trying to do it in Kotlin and Gradle. When I run the project I get a Cannot find proxyClass: error. My build.gradle file has this
annotationProcessor "io.vertx:vertx-codegen:$vertxVersion:processor"
annotationProcessor "io.vertx:vertx-web-api-service:$vertxVersion"
compileOnly "io.vertx:vertx-codegen:$vertxVersion"
compile "io.vertx:vertx-web-api-service:$vertxVersion"`
I can build successfully with Gradle

java.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings() - Gradle links same class twice for Mockito jar

I have configured the following dependencies in the build.gradle file.
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "org.mockito:mockito-all:1.10.19"
And when running the tests getting the following error stack trace.
java.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings()Lorg/mockito/mock/MockCreationSettings;
at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:107)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:81)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:69)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:56)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)
And I've tried to debug it. Found something weird in the IntelliJ linked jar files. Almost most of the classes in the Mockito jar displayed twice.
Refreshing gradle dependencies or cache clear both did not work.
After so many days, I figured out that the issue is with the mockito jar version mismatch.
Changing the version from mockito-all to mockito-core build.gradle to
testCompile "org.mockito:mockito-core:2.24.0"
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.mockito", module: "mockito-all"
}
fixed my problem.
Thanks

Why did Kotlin JSR223 Scripting stop working when I upgraded to Kotlin 1.3.30

In a project that uses the javax.script scripting support added in 1.1 in its unit tests, upgrading the Kotlin language version from 1.3.21 to 1.3.30 caused those tests to fail with the following exception:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingCompilerConfigurationComponentRegistrar
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.makeCompilerConfiguration(KotlinJsr223JvmLocalScriptEngine.kt:72)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.access$makeCompilerConfiguration(KotlinJsr223JvmLocalScriptEngine.kt:38)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:49)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:38)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplCompiler(KotlinJsr223JvmLocalScriptEngine.kt)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:53)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:38)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getLocalEvaluator(KotlinJsr223JvmLocalScriptEngine.kt)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplEvaluator(KotlinJsr223JvmLocalScriptEngine.kt:55)
at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.createState(KotlinJsr223JvmLocalScriptEngine.kt:59)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.createState$default(KotlinJsr223JvmScriptEngineBase.kt:46)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.getCurrentState(KotlinJsr223JvmScriptEngineBase.kt:53)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.nextCodeLine(KotlinJsr223JvmScriptEngineBase.kt:44)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:59)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31)
The relevant lines in build.gradle are:
dependencies {
// ... other stuff ...
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}
where ext.kotlin_version is either "1.3.21" or "1.3.30".
Why did this break, and how can I fix it?
It broke because JetBrains have refactored the scripting functionality into a plugin, and the dependencies required to successfully run Kotlin script through JSR223 have changed.
The relevant issue on the Kotlin bug tracker is KT-30972, which was closed as a duplicate of KT-30986.
The upshot is, you need to adjust the dependencies to include kotlin-scripting-compiler-embeddable.
dependencies {
// ... other stuff ...
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}
the working version nowadays is simply:
dependencies {
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223:${Deps.JetBrains.Kotlin.VERSION}")
}
which pulls in all necessary dependencies transitively.
Also the META-INF/services/javax.script.ScriptEngineFactory File seems not to be necessary if doing so.

IntelliJ IDE 2018.3 Ultimate + Gradle 5.2.1 AND compileOnly

I was about building a gradle 5 project in IDEA.
The lombok dependency was set to compileOnly in the build.gradle file and running it resulted in success from command line and IDEA gradle tool as well.
"Funny" fact, that lombok isn't included in Source Sets, so my lombok imports are failing....
I googled for it, and in theory since IDEA 2017.2 + Gradle 4 it's a fixed issue, IDEA should pick up compileOnly dependencies as well.
In the reality, it does not work.
Any Gradle plugin, or idea to solve this issue? :)
Thanks.
ui.:
VERSION 1
Using compileOnly & annotationProcessor both for prod code and tests resulted in
from command-line, gradle is able to run everything with SUCCESS
from IDEA, it's impossible, imports are failing with lombok
VERSION 2
Using compile & annotationProcessor
from command-line, gradle is able to run everything with SUCCESS
from IDEA, imports are OK, everything is fine
dependencies {...compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")...}
According to https://projectlombok.org/setup/gradle
you need to write in your build.gradle
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.6'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
}
It works for me
You can upgrade the IDEA version to 2019.1 or use the 4.x version of Gradle.

Cannot import a groovy class using gradle

I cant seem to get this (github_link) class imported into my gradle groovy project for testing (Unable to resolve class compile error), Even though the package is coming up in eclipse
import org.openehealth.ipf.platform.camel.ihe.ws.StandardTestContainer
I have the testCompile dependency to the containing jar from jcenter (link)
testCompile 'org.openehealth.ipf.platform-camel:ipf-platform-camel-ihe-ws:3.3.0'

Resources