Questions tagged [kotest]

For questions related to the Kotlin testing framework 'Kotest', which was formerly known as Kotlintest.

Kotest is an open-source testing framework for Kotlin: https://github.com/kotest/kotest/

107 questions
3
votes
1 answer

How to add coverage report (JaCoCo) to kotest based using build.gradle.kts?

I use Kotlin for server side, and I want to add test coverage (by using JaCoCo but can be any other open source). At the moment, I don't find any documentation to explain how to enable/add coverage report to kotlin project based on kotest which…
Shai M.
  • 1,284
  • 4
  • 17
  • 30
3
votes
1 answer

Kotlin Flow: Testing hangs

I am trying to test Kotlin implementation using Flows. I use Kotest for testing. This code works: ViewModel: val detectedFlow = flow { emit("123") delay(10L) emit("123") } Test: class ScanViewModelTest : StringSpec({ "when…
vrgrg
  • 566
  • 4
  • 17
2
votes
2 answers

Could not create instance of functional test class. Specs must have a public zero-arg constructor

I am working with Kotlin, Micronaut and Kotest5. Setup a functional test directory in gradle. Created functional test in it. Test runs fine, however if I am injecting objects in the test class constructor I am getting this error: Could not create…
Tech Noob
  • 510
  • 1
  • 9
  • 33
2
votes
1 answer

Kotest does not report tests as PASSED in Gradle

I've got the following configuration in my build.gradle.kts: tasks.withType().configureEach { testLogging { events = setOf(PASSED, SKIPPED, FAILED) } } My Kotest tests are similar to these: class MyTests : StringSpec({ …
dominikbrandon
  • 408
  • 4
  • 16
2
votes
1 answer

TransactionalEventListener not invoked in @MicronautTest

Problem description While system end-to-end tests are invoking methods annotated with @TransactionalEventListener, I'm not able to invoke the same methods in narrower tests annotated with @MicronautTest. I've tested numerous variants with both…
Roar S.
  • 8,103
  • 1
  • 15
  • 37
2
votes
2 answers

Kotest test factory and beforeSpec

Update While searching for the optimal solution, I switched temporarily to an approach using a dedicated test factory that performs the init in combination with forAll. In this way, I don't have to repeat the init code in every test factory. fun…
Roar S.
  • 8,103
  • 1
  • 15
  • 37
2
votes
2 answers

IntelliJ Kotest doesn't show tests failed with exception

Code I have the following three tests: import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe class Example { fun blah(number: Int): Int { if (number == 1) { throw IllegalArgumentException() …
Jaroslaw Pawlak
  • 5,538
  • 7
  • 30
  • 57
2
votes
1 answer

Is there a Kotest assertion to test if a list contains some element with a given property?

I have two objects that have some features in common that I would like to compare data class Pet(val colour: String, val owner: Human, val legCount: Int) data class Car(val colour: String, val owner: Human, val isElectric: Boolean) I would like to…
mooglin
  • 500
  • 5
  • 17
2
votes
2 answers

Assert that every object property matches given predicate in kotlin test

I have a collection of objects: data class WeatherForecast( val city: String, val forecast: String // ... ) I would like to test that each and every item matches given predicate on field. Is there any assertion in kotlintest assertions…
pixel
  • 24,905
  • 36
  • 149
  • 251
2
votes
1 answer

Run tests in single Spec in parallel ini kotest

I wanted to run kotest in the same spec in parallel. I read the below section in the documentation. But it says you can run only specs in parallel, tests in the single spec will always run…
Ankit
  • 169
  • 1
  • 4
  • 16
2
votes
0 answers

Class cast exception happened when resttemplate postforobject is mocked with MockK

I have an error when I mock restTemplate.postForObject method with a specific flavor of java. With java version 11.0.11.j9-adpt: o.mockk.MockKException: Class cast exception happened. Probably type information was erased. In this case use `hint`…
2
votes
2 answers

"the expression is unused" when using kotest in intellij

With this kotlin test written with Kotest, IntelliJ shows the warning "The expression is unused" and syntax coloration is not working. Also, when running the tests, the test is not found. class TalentMatchServiceSpec : StringSpec() { init { …
Thomas Martin
  • 678
  • 8
  • 19
2
votes
1 answer

Using LiveDataTestUtil with Kotest

I have been reading through the LiveDatatestUtil.kt provided as part of the Android Architecture Components Samples, and I have been trying to work out how to test Events with it within Kotest, so far as possible. Mainly because (right now) Kotest…
2
votes
1 answer

TestContainers and Mysql : Access denied for user ''@'172.17.0.1' (using password: NO)

I wrote a simple repository to test Kotlin Exposed with TestContainers. The database that I use is mysql. Here is my code : class StudentsRepositoryTest: ShouldSpec({ val container = getMysqlContainer() val mysqlJdbcUrl =…
Dimitri
  • 8,122
  • 19
  • 71
  • 128
2
votes
1 answer

Is there a way to stop a micronaut scheduled job between tests?

I have an application that dynamically schedules jobs based on properties. It listens for the ServiceReadyEvent and then schedules the job. Below is a small example that would get added to the context via a factory. class JobsLoader( …
Jake Luby
  • 1,718
  • 5
  • 16