https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotest
  • b

    bbaldino

    05/16/2022, 6:40 PM
    I’m getting
    No tests found for given includes
    when trying to run a single kotest test inside a gradle project--I assume this must be something dumb I’m missing but after googling around a bit I still haven’t seen anything that addresses it. I do have
    tasks.withType<Test>().configureEach {
        useJUnitPlatform()
    }
    in build.gradle.kts
    s
    • 2
    • 66
  • e

    Eric Ampire [MOD]

    05/17/2022, 11:57 PM
    I have just published an article that can help you get started with Property Based Testing. https://ericampire.com/create-powerful-tests-using-property-based-testing
    🙌 4
    :party-parrot: 1
    :thank-you: 1
    s
    j
    • 3
    • 2
  • b

    Brian Estrada

    05/19/2022, 6:16 AM
    Anyone have any luck running kotest on kotlin native?
    a
    • 2
    • 4
  • p

    phldavies

    05/23/2022, 2:30 PM
    Is there any way to run a JUnit test class when using kotest? We have an abstract base class that defines lifecycle/tests for a component using JUnit5 (from a library we don’t control) but we’re using kotest in our project.
    w
    d
    • 3
    • 3
  • c

    charleskorn

    05/23/2022, 10:51 PM
    Are there any known issues with setting
    assertionMode
    to
    Error
    and tests that use coroutines? My test uses coroutines and makes assertions (and the test fails if the assertions fail), but I still get a
    Test … did not invoke any assertions
    error.
    j
    • 2
    • 4
  • d

    Davio

    05/24/2022, 8:52 AM
    Hello everyone, I have a question about Kotest; all the documentation examples use (public) classes, such as
    class MyTest: SomeSpec({ ... })
    But in e.g. vanilla JUnit classes are always recommended to be internal (package private) and I found out that this works as well:
    internal class MyTest: SomeSpec({ ... })
    Is there a reason test classes should be public or can/should they be internal?
    w
    m
    • 3
    • 5
  • e

    Eric Ampire [MOD]

    05/24/2022, 10:59 AM
    Hi folks, when you read a book on testing it often says that a test must be repeatable In the case of property based testing, the data is generated automatically, can we say that these tests are repeatable?
    b
    w
    +2
    • 5
    • 6
  • r

    Roy Åne Sylthe

    05/24/2022, 2:51 PM
    Good evening! Does Kotest have a default test filter? I've updated from 4.6 to 5.3 and now a test class named
    ConfigTest
    is being run as part of my integration tests. I have no explicit test filter in gradle telling it to pick up
    *Config*
    as part of the integration test task, so I'm at a complete loss as to why this is happening after updating Kotest.
    s
    • 2
    • 1
  • j

    Jonathan Lennox

    05/26/2022, 7:36 PM
    I'm porting some unit tests from Kotest 4.6 to Kotest 5.3, and I've discovered that one of my tests is taking a hugely longer time to run with the new kotest - i.e. from 1.5 seconds with kotest 4.6, to 90 seconds with kotest 5.3 on my test AWS host. Any idea what could be causing this?
    s
    • 2
    • 58
  • s

    Sergio Crespo Toubes

    05/27/2022, 11:17 AM
    Hello, how is the best way to do this with kotest?
    val item = turbineState.awaitItem()
    item.showProgress.shouldBe(false)
    item.selectedItem.shouldBe(-1)
    item.filteredLocations.count().shouldBe(2)
    I tried this code but is not working...
    turbineState.awaitItem().should {
       !it.showProgress &&
       it.selectedItem == -1 &&
       it.filteredLocations.count() == 2
    }
    e
    d
    • 3
    • 3
  • e

    Emil Kantis

    05/31/2022, 7:21 AM
    Is it possible to attach logs to a test case/result from a
    TestListener
    ?
    j
    • 2
    • 2
  • w

    wasyl

    06/03/2022, 1:52 PM
    🎩 Quick question, is support for IJ 2022.2 EAP planned?
    e
    s
    • 3
    • 2
  • s

    sam

    06/03/2022, 4:16 PM
    I added a massive hack to make it work. There is zero chance gradle fix the bugs. They simply don't care.
    s
    l
    c
    • 4
    • 65
  • r

    Rob Elliot

    06/06/2022, 5:44 PM
    I'm writing a selenium test in kotest - I'm implementing a
    TestListener
    so that if
    TestResult.isErrorOrFailure
    I can use
    RemoteWebDriver.getScreenshotAs
    to capture the output. However, I need to save the file somewhere... is there a way to work out an output directory for kotest? I guess it would be very dependent on how kotest was bring run (gradle, maven, stadalone, whatever), so probably not, but thought I'd ask if anyone had any bright ideas.
    j
    s
    • 3
    • 5
  • r

    Rob Elliot

    06/06/2022, 6:33 PM
    Another q - is there a way to declare that a listener depends on another listener so it's beforeTest happens after, and it's afterTest happens before, the methods on the other listener?
    j
    • 2
    • 2
  • a

    Alexandre Brown

    06/07/2022, 1:16 PM
    Hello, is using
    runTest
    still needed when using Kotest with
    testCoroutineDispatcher = true
    ? Context : I would usually have a class with
    coroutineScope: CoroutineScope
    in the constructor
    class MyClass(private val coroutineScope: CoroutineScope): CoroutineScope by coroutineScope { }
    then in my test I would do something like this :
    "myTest using string spec" {
        runTest {
            val myClass = MyClass(this)
        }
    }
    So that it uses the Coroutine scope from
    runTest
    . I see that
    StringSpec
    has a test scope so that I can do the same but without wrapping my test with
    runTest
    , is it safe to do so? I want to ensure the are no coroutines leaks between test to avoid flaky tests.
    "myTest using string spec" {
        val myClass = MyClass(this)
    }
    s
    • 2
    • 3
  • j

    James Eschner

    06/09/2022, 4:00 PM
    Just bumped to Kotlin
    1.7.0
    and am seeing this in Kotest:
    Found interface kotlin.time.TimeMark, but class was expected
    java.lang.IncompatibleClassChangeError: Found interface kotlin.time.TimeMark, but class was expected
    	at io.kotest.engine.spec.interceptor.SpecFinishedInterceptor.intercept-0E7RQCE(SpecFinishedInterceptor.kt:37)
    	at io.kotest.engine.spec.interceptor.SpecFinishedInterceptor$intercept$1.invokeSuspend(SpecFinishedInterceptor.kt)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    do I need to wait for a new Kotest version? ** Not a contribution
    s
    s
    +3
    • 6
    • 19
  • v

    Viktor Orlyk

    06/11/2022, 5:06 PM
    Hi, all) want to use envs in tests but faced some problems, can you please help? More details in stackoverflow question. https://stackoverflow.com/questions/72586298/kotest-change-environment-variables
    j
    e
    s
    • 4
    • 6
  • m

    M S

    06/12/2022, 9:41 AM
    Hi, community. Can someone help me? I need an example of using Kotest with PiTest for JDK 1.8. The extension 'kotest-extensions-pitest' requires JDK 11.
    • 1
    • 2
  • i

    Ido Flax

    06/15/2022, 1:35 PM
    Hello ppl. Is there anyway to get transactions to rollback for tests in kotest + spring without using annotationSpec?
    l
    t
    • 3
    • 15
  • s

    SimonT

    06/17/2022, 9:00 AM
    Hello everyone. I wanted to ask you something related to Kotest. I have been having issues lately that when I run my unit tests with kotest everything is green, but if I explore the builds I get some errors but I can't know about the build errors unless I explore the build output on my tests. I noticed that my tests failed in the CI that's how I discovered this issue. In the few places that this happened was because the class had some code in the init block. I wanted to know if there exists any flag or any way to make the tests fail locally so I know there are issues before running the CI. Thank you in advance.
    l
    • 2
    • 6
  • m

    Matthew Wright

    06/17/2022, 3:56 PM
    👋 I was half expecting kotest to play nice with Junit5 extensions (such as Selenium-Jupiter) with at least
    AnnotationSpec
    but it doesn't appear kotest supports
    ParameterResolver
    (Junit docs). Am I understanding this correctly?
    s
    a
    • 3
    • 9
  • a

    abendt

    06/20/2022, 3:30 PM
    hi @sam, kotest provides the `shouldMatchEach`matcher for collections. We found it helpful to have a similiar matcher for Maps and implemented it on our own.
    fun <K, V> Map<K,V>.shouldMatchAll(vararg matcher: Pair<K, (V) -> Unit>)
    Do you think this is generally helpful and would you accept a PR with that matcher?
    s
    e
    • 3
    • 6
  • w

    wasyl

    06/22/2022, 2:23 PM
    🎩 I don’t intend to rush, but I wanted to ask if there’s some rough estimate for https://github.com/kotest/kotest/issues/2915? I don’t know how complex the issue is and I don’t understand the framework enough to contribute, I’d just like to know, if possible, rough timeline to know how to plan my work 🙂 Also I’m wondering if it has something to do with other issues related to tests naming like https://github.com/kotest/kotest/issues/3068
    s
    e
    • 3
    • 7
  • i

    iamsteveholmes

    06/22/2022, 9:53 PM
    Hey folks! Anyone got examples of code Katas using kotest? I haven’t been able to find any so far…
    l
    • 2
    • 3
  • i

    Ivan Pavlov

    06/22/2022, 10:01 PM
    Does beforeSpec work for js tests? This test actually runs and fails with
    IllegalStateException: IN TEST
    . The same test in jvm works as expected failing with
    IllegalStateException: IN BEFORE SPEC
    class SimpleTest : FunSpec({
        beforeSpec {
            error("IN BEFORE SPEC")
        }
        test("test") {
            error("IN TEST")
        }
    })
    s
    • 2
    • 1
  • d

    Didier Villevalois

    06/26/2022, 1:38 PM
    Hi! Bumping from kotest 5.0.0 to 5.3.1, I now have kotest complaining that "Nested tests are not supported" when running my tests on JS target. I understand the explanations @sam gave about the
    describe
    levels not supporting async lambdas in JS test frameworks. Now I need to understand why we need to have non-test-case levels suspending on the Kotest side?
    b
    • 2
    • 2
  • r

    Richard Gomez

    06/29/2022, 5:46 PM
    I recently upgraded to Kotlin 1.7.0 & Kotest 5.3.1, and I'm now getting a strange error. I don't understand why it's trying to pull in
    kotlinx-coroutines-bom:jar
    , which obviously wouldn't exist (pom only).
    Could not find artifact org.jetbrains.kotlinx:kotlinx-coroutines-bom:jar:1.6.3
    This probably isn't an error with Kotest, but it's the closest lead I have right now.
    maven.log.txt
    e
    m
    • 3
    • 14
  • r

    reactormonk

    07/06/2022, 9:41 AM
    I'm generating with tiny types, getting
    the target size requirement of 63 could not be satisfied after 630 consecutive samples
    This is the type I'm generating, both fields are enum classes:
    data class PollingSettings(val polling: EnumSet<AutomaticPPICPolling>, val interval: PICCPollInterval)
    Reducing the number of iterations didn't help
    s
    • 2
    • 8
  • k

    Klitos Kyriacou

    07/06/2022, 3:26 PM
    Does Kotest have the equivalent of AssertJ's
    extracting
    feature? For example, in AssertJ I can do this:
    assertThat(foo)
        .extracting(Foo::id, Foo::description)
        .containsExactly(1234, "this is a foo")
    The closest I could find was
    shouldBeEqualUsingFields
    but that's not suitable, as it requires another Foo argument which I can't easily construct; I only have the naked property values.
    j
    l
    +2
    • 5
    • 24
Powered by Linen
Title
k

Klitos Kyriacou

07/06/2022, 3:26 PM
Does Kotest have the equivalent of AssertJ's
extracting
feature? For example, in AssertJ I can do this:
assertThat(foo)
    .extracting(Foo::id, Foo::description)
    .containsExactly(1234, "this is a foo")
The closest I could find was
shouldBeEqualUsingFields
but that's not suitable, as it requires another Foo argument which I can't easily construct; I only have the naked property values.
j

Jim

07/06/2022, 3:28 PM
I'd do:
all(foo) {
  it.id shouldBe 1234
  it.description shouldBe "stuff"
}
l

LeoColman

07/06/2022, 3:30 PM
I'd go with
assertSoftly(foo) {
    it.id shouldBe 1234
    it.description shouldBe "stuff"
}
This way you'd get every failing assertion
j

Jim

07/06/2022, 3:30 PM
Yeah all ~= assertSoftly
:kotlin-intensifies-purple: 2
e

Emil Kantis

07/06/2022, 3:31 PM
Agree,, but you don't need to use
it
iirc? the assertSoftly should lambda should already be scoped to the subject?
j

Jim

07/06/2022, 3:32 PM
Yeah I couldn't remember if all was
T.() -> Unit
or
(T) -> Unit
🤪
😂 1
It might even be
T.(T)
I've seen that here and there
e

Emil Kantis

07/06/2022, 3:33 PM
Funny, yeah it seems to be
test("hello") {
         val p = Point(0.0, 3.0)
         assertSoftly(p) {
            x shouldBeGreaterThan -1.0
            it.y shouldBe 3.0
         }
      }
👍 1
j

Jim

07/06/2022, 3:34 PM
I like both, since you have access to the lambda arg you can destructure a pair or something with a useful name
s

sam

07/06/2022, 3:37 PM
(T).T -> is a bizarre signature lol
😛 1
e

Emil Kantis

07/06/2022, 3:41 PM
good point @Jim 🙂
k

Klitos Kyriacou

07/06/2022, 3:42 PM
Yes, you can do that, but then the assertion failure message is something like "expecting 123 to be 456". The advantage of AssertJ's
extracting
method is that it tells you "expecting id to be 456 but was 123." Much clearer and much more helpful.
🤔 2
j

Jim

07/06/2022, 3:49 PM
Maybe a reflection powered assertion could get us there with an auto clue
l

LeoColman

07/06/2022, 4:29 PM
(T).T -> is a bizarre signature lol
"I want T both as a receiver and as a parameter". The only way to do it really is crying before, hence the T_T
e

Emil Kantis

07/06/2022, 5:53 PM
assertProperties(p) {
  Point::x shouldBe 0.0
  Point::y shouldBe 3.0
}
doable? @Jim? 🙂
j

Jim

07/06/2022, 5:55 PM
I think I did something like this at work, let me see
s

sam

07/06/2022, 6:26 PM
We should add a compiler plugin that is better with shouldBe
so
x shouldBe y
can capture the variable name on the left
There's power assert, which is cool because it builds a tree of the intermediate values, but I think we could get half way there with something quicker that just captures the variable names, which is mostly what I want to see.
j

Jim

07/06/2022, 6:29 PM
fun isOdd(x: Int) = x % 2 != 0

data class IntWrapper(val value: Int) {
    fun isOddWrapper() = isOdd(value)
}

class SampleTests : FunSpec({
    test("function pointer") {
        all(IntWrapper(1)) {
            its { ::isOddWrapper } shouldBe false
            its { ::isOdd } shouldBe false
        }
    }
})

data class ShouldBeLeft<R>(val name: String, val actual: R) {
    infix fun shouldBe(expected: R) {
        withClue("Expected property $name to equal $expected but was $actual") {
            actual shouldBe expected
        }
    }
}

infix fun <T, R> T.its(kfunc: (T) -> KFunction<R>): ShouldBeLeft<R> {
    val f = kfunc(this)

    return if ((f as? FunctionReferenceImpl)?.boundReceiver != null) {
        ShouldBeLeft(f.name, f.call())
    } else {
        ShouldBeLeft(f.name, f.call(this))
    }
}
damn, too slow 😂
Expected property isOddWrapper to equal false but was true
java.lang.AssertionError: Expected property isOddWrapper to equal false but was true
expected:<false> but was:<true>
only works with JVM I think though
View count: 58