Sample of a simple Quarkus application written in Kotlin. Shows how Junit 5 and MockK may be used for mocking CDI beans.
Note: A detailed blog post where the motivation and whole set up is described can be found here: https://www.novatec-gmbh.de/blog/testing-quarkus-with-kotlin-junit-and-mockk
You can run your application in dev mode that enables live coding using:
./gradlew quarkusDev
The application can be packaged using:
./gradlew build
It produces the quarkus-kotlin-mockk-1.0.0-SNAPSHOT-runner.jar
file in the /build
directory.
Be aware that it’s not an über-jar as the dependencies are copied into the build/lib
directory.
If you want to build an über-jar, execute the following command:
./gradlew build -Dquarkus.package.type=uber-jar
The application is now runnable using java -jar build/quarkus-kotlin-mockk-1.0.0-SNAPSHOT-runner.jar
.
The tests can be either executed by running the Gradle command
./gradlew clean test
Or directly as usual in the IDE, e.g. IntelliJ.
E.g. Run
> RestControllerTestsWithBeforeEach.kt
etc.