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
  • m

    Michael Strasser

    03/29/2022, 10:32 PM
    Kotest is in the latest Thoughtworks Radar! A number of Thoughtworkers (including myself) use Kotest regularly and recommend using it for Kotlin development. Congratulations on an excellent testing framework! https://www.thoughtworks.com/radar/languages-and-frameworks?blipid=201911021
    🎉 14
    :kotlin-intensifies: 5
    :kotest: 1
    s
    • 2
    • 1
  • m

    mitch

    03/30/2022, 5:54 AM
    question @sam a co-worker of mine just ran into a problem like below
    test("should print out failing inputs and shrinks when a function throws") {
          suspend fun functionThatUnexpectedlyThrows() { throw RuntimeException("aaaa") }
          checkAll(Arb.bigInt(4, 4)) { value ->
             functionThatUnexpectedlyThrows()
          }
       }
    and then I realized that we don’t report the inputs or attempt any shrinking to the users when the exception is not kotest’s assertion errs. i.e.
    Property failed after 1 attempts
    java.lang.AssertionError: Property failed after 1 attempts
    
    Repeat this test by using seed 320358835705021305
    
    Caused by RuntimeException: aaaa
    if that function was wrapped around
    shouldNotThrowAny { .. }
    then that’ll print out the inputs and properly shrunk it. it’s written here https://github.com/kotest/kotest/blob/aba6984d6a08530e931274f7a9f6e3b62a66b681/kot[…]perty/src/commonMain/kotlin/io/kotest/property/internal/test.kt is this by design? or should we fix that? if you reckon that’s a bug i can raise an issue and raise a fix PR?
    s
    • 2
    • 2
  • a

    André Martins

    04/01/2022, 9:14 AM
    Hey when generating an arbitrary domain model instance how can one lock some properties? Suppose I have a Student data class with an id, number, name and some other fields. If I have the following generator
    fun Arb.Companion.student(): Arb<Student> = arbitrary { rs ->
        Student(
            id = Arb.uuid(V4,false).next(rs)
            name = Arb.string().next(rs),
            number = <http://Arb.int|Arb.int>().next(rs), ...
        )
    }
    What can I add here to lock the number I which my generated student have?
    Arb.student().<here>?
    // Something like
    Arb.student().with(number, 123)
    Anyway I can do this?
    e
    p
    l
    • 4
    • 12
  • l

    LeoColman

    04/02/2022, 5:48 PM
    Hey guys! When using assertion
    shouldBeFailure
    , the error message I get is
    java.lang.AssertionError: Result should be a failure but was kotlin.Unit
    While I actually expected it to be more significant that it's a Success, like:
    java.lang.AssertionError: Result should be a failure but was Success(kotlin.Unit)
    This is due to the fact that
    BeFailure
    uses
    getOrNull
    in the
    Result
    instead of
    toString
    . I think it would be better to replace it, but I don't know. What do you think? I can open an issue to discuss this further in the Kotest repository
    m
    • 2
    • 2
  • j

    James Eschner

    04/04/2022, 9:32 PM
    How do I use the SystemEnvironmentProjectListener (or really any externally defined project listener) in my project? I found a README that says to do this:
    class ProjectConfig : AbstractProjectConfig() {
    
        override fun listeners(): List<TestListener> = listOf(SystemEnvironmentProjectListener("foo", "bar"))
    
    }
    but AbstractProjectConfig::listeners is deprecated and the deprecation message, “`Use extensions."` , isn’t the most helpful. I would like to define the listener once for the whole project. * Not a contribution *
    e
    • 2
    • 4
  • j

    julian

    04/05/2022, 2:09 AM
    When I run a single test of a spec that contains multiple tests, Kotest generates output for every ignored test. It's challenging to wade through all that logging when I'm looking for the output of print statements that I've added to the code under test in order to debug. Is there a way to turn off the logging? Otherwise, how could I have the output from print statements be associated with the test that was run instead of the spec containing all the tests?
    j
    b
    • 3
    • 37
  • p

    Peter

    04/05/2022, 7:35 AM
    anyone else having a problem with with
    5.2.2
    - i think it may be related to the new
    1.6.1
    coroutine release from yesterday?
    s
    o
    c
    • 4
    • 13
  • w

    wasyl

    04/05/2022, 8:24 PM
    We’re just migrating to Kotest 5.x, and I found some behavior that I can’t figure out if it’s a bug or not. I managed to trim it down to the following repro, and as far as I can see it’s triggered by two tests having the same name (as seen in the test). When I change one of the duplicated tests names, the test pass. Code and error details in 🧵
    e
    • 2
    • 6
  • i

    iamsteveholmes

    04/06/2022, 3:53 PM
    Anyone working with KMM or Multiplatform? It seems that Kotlin 1.6.20 broke Kotest references in Android Studio at least on my environment. This seems related to an old bug I filed 8 months ago:
    • 1
    • 1
  • i

    iamsteveholmes

    04/06/2022, 3:58 PM
    Here’s the bug: https://youtrack.jetbrains.com/issue/KT-48148
    s
    j
    • 3
    • 3
  • t

    tim

    04/11/2022, 8:45 AM
    Hi ya, is there an a way to run some “after all tests / specs” logic? At the moment i’m using
    Runtime.getRuntime().addShutdownHook(…)
    but was curious if there’s something exposed by kotest to more easily accomplish this?
    w
    s
    • 3
    • 6
  • b

    Big Chungus

    04/11/2022, 11:31 AM
    Is there any logging capabilities embedded within the framework that I could use in my tests? I'd like to log some intermediate test outputs at debug level to toggle on when something goes wrong.
    j
    • 2
    • 5
  • m

    mcpiroman

    04/11/2022, 4:19 PM
    How do I properly use the same `withData`for multiple tests? 🧵
    s
    • 2
    • 7
  • r

    Richard Gomez

    04/11/2022, 7:40 PM
    Perhaps this is more of a mockk question, but I've noticed that records from mocks and spys tend to bleed over between tests, even with
    confirmVerified
    or
    unmockX()
    between cases. 🧵
    l
    • 2
    • 4
  • m

    Min Tikim

    04/11/2022, 8:27 PM
    posted on stackoverflow but has anyone ran into similar issue here? I'm new to springboot and kotest https://stackoverflow.com/questions/71833886/springboot-test-fails-to-run
    s
    • 2
    • 5
  • a

    alightgoesout

    04/12/2022, 5:09 PM
    is there a plugin for continuous testing, as Ncrunch for C#? the auto-test function in Intellij is not as useful
    l
    r
    d
    • 4
    • 5
  • f

    Filip Piechowski

    04/13/2022, 9:40 AM
    Hi. I have a problem i’m struggling with for a few days. I want to create a DSL-like
    TestFactory
    builder, that would nest further steps declared by user in a lambda as the last parameter of my test factory. In my specific case that would look like this:
    class MySpec : FreeSpec({
        include(replicatorSpec(...) { // this: ReplicatorTestFactoryConfiguration extending TestFactoryConfiguration(), FreeSpecRootScope
            parent(...) { // this: ReplicatorTestFactoryConfiguration.AfterParent extending TestFactoryConfiguration(), FreeSpecRootScope
                create(...) { // this: ReplicatorTestFactoryConfiguration.AfterCreate extending TestFactoryConfiguration(), FreeSpecRootScope
                    update(...)
                }
            }
        )}
    })
    
    inline fun RootScope.replicatorSpec(
        ...,
        crossinline configure: ReplicatorTestFactoryConfiguration.() -> Unit = { }
    ) = freeSpec {
        <http://logger.info|logger.info> { "replicatorSpec" }
    
        beforeSpec {...}
    
        val configuration = ReplicatorTestFactoryConfiguration(...)
    
        configuration.configure()
    
        afterSpec {...}
    }
    
    inline fun ReplicatorTestFactoryConfiguration.parent(
        ... ,
        crossinline then: ReplicatorTestFactoryConfiguration.AfterParent<P>.() -> Unit = {}
    ) { ... }
    
    inline fun ReplicatorTestFactoryConfiguration.AfterParent.create(
        ... ,
        crossinline then: ReplicatorTestFactoryConfiguration.AfterParent<P>.AfterCreate<P, COUT>.() -> Unit = { }
    ) { ... }
    
    inline fun ReplicatorTestFactoryConfiguration.AfterParent.AfterCreate.update(...) { ... }
    But when running tests and putting debug FreeSpec test scopes (
    "debug" - { }
    ) i see that execution gets only to the
    replicatorSpec(...)
    and the FreeSpecScopes defined in there, but anything further like the code defined in lambda. How can I create such a
    s
    • 2
    • 7
  • l

    Lidonis Calhau

    04/14/2022, 2:41 PM
    Is there an "or" matcher. I would like to test that a json key is absent or false.
    shouldContainJsonKeyValue("key", false) or shouldNotContainJsonKeyValue("key")
    s
    • 2
    • 4
  • p

    peekandpoke

    04/18/2022, 8:12 AM
    Hi there! I am having problems with jsTest and jsBrowserTest in a multiplatform project. On my machine tests are no longer executed for JS. When I create a test like
    "FAIL!" {
       fail("BOOOM!")
    }
    I still see all tests being successful. The test suite also worked last week and the JS and Common tests where executed properly and suddenly stopped doing so. Does anyone have an idea what is wrong here. I am running on Ubuntu 20.04 and Kotest 5.2.3, Kotlin 1.6.20. I also know that my browsers where updated last week... So yeah am I lost here. Any help, ideas or pointers is very much appreciated!
    ☝️🏻 1
    s
    j
    b
    • 4
    • 70
  • t

    thana

    04/18/2022, 9:31 AM
    Hi! I was wondering if there are any recommended formatter settings in conjunction with kotest. when using the standard kotlin formatter settings from intellij there is really much whitespace in front of all lines...
    s
    • 2
    • 8
  • s

    sam

    04/18/2022, 12:09 PM
    Wrote a quick blog on avoiding mocks by using Test Containers and Kotest https://medium.com/@sam_57450/unitigration-testing-with-kotest-and-test-containers-55b7ad28f615
    :nice: 5
    t
    r
    • 3
    • 5
  • t

    thana

    04/18/2022, 3:50 PM
    Is there a way to twek the kotest plugin so i can navigate to the failing assertion by double clicking it in the results view (as i am used to do from plain junit tests)?
    s
    j
    • 3
    • 12
  • c

    christophsturm

    04/19/2022, 8:36 AM
    what does Arb stand for?
    e
    • 2
    • 2
  • a

    André Martins

    04/21/2022, 9:37 AM
    Hey suppose I have a Student like
    data class Student(val id: Int, val name: String)
    and I’m trying to build a Arb of Student like
    fun Arb.Companion.student(
        id: Arb<Int> = positiveInt(),
        name: Arb<String> = string()
    ): Arb<Student> = arbitrary { rs ->
        Student(
            id.next(rs),
            name.next(rs) // or name.bind() and ignore rs?
        )
    }
    Should I call
    bind
    or
    next
    with the current randomSource?
    e
    m
    • 3
    • 13
  • j

    James Eschner

    04/21/2022, 2:44 PM
    Ever since my upgrade to 2022.1 (Ultimate Edition) I am seeing “Invalid value: -1” errors trying to run Kotest tests from the gutter (using the play button). My project uses gradle and I suspect that could be a cause as well. This is making is very difficult to run tests locally 😞 ** Not a contribution
    ➕ 1
    s
    • 2
    • 6
  • a

    Adam S

    04/30/2022, 8:05 AM
    Hi, does anyone have experience of testing an OpenAPI spec using Kotest? I'm asking because I'm very tempted to start creating a Kotest version of Schemathesis, which I've used before to great effect. I'd like a Kotlin version though! I think a Kotest 'OpenAPI' module would work really well. It would parse an OpenAPI spec (Swagger provides a Java parser), and generate random requests, using Arbs. So if a specific response isn't documented, or a parameter marked as 'optional' actually isn't, then the test would fail. Stateful testing (e.g. make sure that after a successful
    POST /user/create
    that
    GET /user/{id}
    works) is possible too. The benefits of this would be • the OpenAPI spec drives the testing, and would be completely separate from the codebase (no need for spec or code generation, which is always limiting) • there's no limitation or restriction on how to implement the API (for example Hikaku doesn't handle many custom implementations) • because the spec can be tested, it would always be up-to-date. I've attached a mock code example. I might work on a proof-of-concept...
    Untitled.cpp
    💡 3
    s
    • 2
    • 5
  • b

    benkuly

    05/03/2022, 12:14 PM
    Are there plans for kotest to support nested javascript tests (mybe runTest allows this)? I hava a huge library with 500 kotest-tests and wanted to enabled JS without loosing advantages of nested tests... (apart from all the work to refactor 500 nested tests to not nested tests).
    s
    • 2
    • 27
  • j

    Juan B

    05/04/2022, 7:23 AM
    Hi all, I'm trying to use Kotest + TestContainers (neo4J database) and I cannot make it work. The error is:
    Not enough information to infer type variable T
    io.kotest.extensions.testcontainers.TestContainerExtension public constructor TestContainerExtension<T : GenericContainer<out T>>(
        container: GenericContainer<out T>,
        lifecycleMode: LifecycleMode
    )
    Adding the test code in the thread 👇 Thanks for any help!!
    s
    • 2
    • 8
  • r

    Rob Elliot

    05/05/2022, 4:04 PM
    Is there a form of
    Map<K, V>.shouldContainAll(expected: Map<K, V>)
    which recurses into any maps in the top level structure?
    s
    e
    • 3
    • 12
  • p

    peekandpoke

    05/12/2022, 2:07 PM
    Has anyone seen the error above before?
    s
    • 2
    • 7
Powered by Linen
Title
p

peekandpoke

05/12/2022, 2:07 PM
Has anyone seen the error above before?
s

Sam

05/12/2022, 2:11 PM
"Internal compiler error" shouldn't ever happen. If you can reproduce it I would report it via kotl.in/issue
p

peekandpoke

05/12/2022, 2:12 PM
Well maybe the kotest gradle plugin is doing something "fancy"?
I can build all other gradle sub-projects ... only the jsTest stuff is broken...
Ok here is the deal: I have an external dependency (kotest-js) that brings in
kotlinx-coroutines-core.1.6.1
And my lib pulls
kotlinx-coroutines-core.1.6.0
Somehow the compiler does not remove the smaller version from the
icCacheMap
which some steps later results in the NPE.
After updating my dep to
kotlinx-coroutines-core.1.6.1
the errors is gone.
So in short: It is a problem in the dependency resolution in the kotlin compiler
https://youtrack.jetbrains.com/issue/KT-52366/KJS-IR-NullPointerException-when-compiling-with-coroutines-and-k
View count: 9