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
17
votes
3 answers

kotlin-test: How to test for a specific type like: "is y instance of X"

How to test if a val/var is of an expected type? Is there something I am missing in Kotlin Test, like: value shouldBe instanceOf() Here is how I implemented it: inline fun instanceOf(): Matcher { return object :…
Chriss
  • 5,157
  • 7
  • 41
  • 75
7
votes
3 answers

How to write beforeEach and beforeClass in kotlintest

Given is the example from kotlin-test github docs, but i don't see beforeEach or beforeClass concept here. I want to understand, How to execute a code/method once before every test How to execute a code/method once before every test class class…
JTeam
  • 1,455
  • 1
  • 11
  • 16
6
votes
3 answers

Kotest with Mockk: How to clear verify count

So I have the following code: When("SMS with location update command is received") { every { context.getString(R.string.location_sms, any(), any(), any(), any()) } returns "loc" …
SMGhost
  • 3,867
  • 6
  • 38
  • 68
4
votes
1 answer

kotest change environment variables

I am writing tests for Ktor app using Kotests, but stumbled into the problem how can I change env variables for tests preferably globally. I have tried adding withEnvironment but it throw quite strange error into me Unable to make field private…
Victor Orlyk
  • 1,454
  • 2
  • 15
  • 27
4
votes
1 answer

Is there a simpler way to test all permutations with Kotest property-based testing?

I'm working with kotlin + Kotest property testing and trying to test all permutations of 2 parameters with list generators like this: "Some test"{ forAll(4 , Exhaustive.collection(listOf( "a", …
janicedn
  • 53
  • 5
4
votes
1 answer

Multiple assertions (assertAll) - Kotest

Is any way to check multiple assertions in Kotest in DSL style - without Assertions.assertAll method from JUnit? Can I write something like firstValue shouldBe 1 and secondValue shouldBe 2 Instead of assertAll( { fistValue shouldBe 1 }, {…
Gustlik
  • 350
  • 2
  • 12
3
votes
1 answer

Mockk verify fails when checking called and wasNot called

I am trying to verify that a function was not called using the following: verify { managementService.deleteUser(any()) wasNot Called } That verification fails with the message: Verification failed: call 1 of…
HotN
  • 4,216
  • 3
  • 40
  • 51
3
votes
2 answers

Assert that list contains elements with specific properties in any order

In Junit5 i used the following snippet often to test if a collection contains elements that fullfill certain criteria: assertThat("The list of addresses", addresses.getAddressReferences(), containsInAnyOrder( allOf( …
Chris
  • 7,675
  • 8
  • 51
  • 101
3
votes
1 answer

Ktor testing Fail to serialize body. Content has type: class ... but OutgoingContent expected

so trying to understand how I can make testing ktor app with testcontainers this is my code package com.app import com.app.base.db.DbFactory import com.app.features.auth.RegisterDTO import com.app.plugins.* import…
Victor Orlyk
  • 1,454
  • 2
  • 15
  • 27
3
votes
2 answers

Kotest and kotlinx-coroutines-test Integration

I use the Funspec testing style in kotest and I get a coroutineScope injected automatically by the framework as shown below. class MyTestSpec: FunSpec() { init { test("test event loop") { mySuspendedFunction() // a…
rogue-one
  • 11,259
  • 7
  • 53
  • 75
3
votes
2 answers

Handle multiple exceptions in Kotlin Kotest eventually

As per kotest docs: https://github.com/kotest/kotest/blob/master/doc/nondeterministic.md You can tell eventually to ignore specific exceptions and any others will immediately fail the test. I want to pass multiple exceptions to eventually that I…
3
votes
1 answer

How do I "obtain transaction-synchronized Session for current thread" in a Micronaut / Kotest / Hibernate test

I'm trying to clean up a database used by my component tests after each one so it's blank for the next. To do this I've got something like the following: @MicronautTest class ExampleTest( private val entityManager: EntityManager ) :…
MysteriousWaffle
  • 439
  • 1
  • 5
  • 16
3
votes
1 answer

Kotest - Generate exhaustive object permutations with no repeat

I want to be able to generate an exhaustive permutation of objects. Imagine the following object data class Person (name: String, age: Int) For testing purposes, I want to restrict the name to 3 values. Mohammad, Nasir, Rasul and age to 4 values.…
Nasir
  • 2,984
  • 30
  • 34
3
votes
1 answer

Why IntelliJ Kotest plugin does not work well?

I've installed the Kotest plugin (1.1.22-IC-2020.3) for IntelliJ (2020.3). It allows me to create Kotest tests for/from my Kotlin classes, but those tests are not runnable from the test classes. If I create a new Kotest run configuration I can run…
3
votes
1 answer

Kotest breaks gradle's :test task with java.lang.IllegalArgumentException: Received a failure event for test with unknown id

I'm getting started with unit tests in Kotlin using Kotest. I use the following technologies that integrate somehow with Kotest: Kotest itself Kotlin / JVM Gradle Allure Pitest IntelliJ IDEA Plugin "Kotest" In gradle, I included the following…
Raphael Tarita
  • 770
  • 1
  • 6
  • 31
1
2 3 4 5 6 7 8