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

    Sebastian Schuberth

    11/27/2021, 2:36 PM
    After upgrading to Kotest 5.0.0 (from 4.6.3) I'm seeing some unit test fail that use Wiremock to start / stop a server in
    beforeSpec {}
    /
    afterSpec {}
    , see https://dev.azure.com/oss-review-toolkit/ort/_build/results?buildId=6317&view=ms.vs[…]ld-test-results-tab&runId=38928&resultId=100025&paneView=debug. Is anyone else experiencing problems with Kotest 5 & Wiremock?
    b
    e
    9 replies · 3 participants
  • s

    Sebastian Schuberth

    11/28/2021, 9:45 AM
    I'm running into more troubles after migrating to Kotest 5.0.0. Can it be that the order in which
    beforeTest
    from a
    TestListener
    vs. a function from within the test spec are being called? I'm now seeing
    beforeTest
    from a `TestListener`being caller after the
    beforeTest
    overridden in a test spec, whereas I believe the order was different before. Is that expected?
    s
    19 replies · 2 participants
  • s

    Sebastian Schuberth

    11/28/2021, 10:06 AM
    Yet one more thing: I just realized that
    beforeTest()
    in a
    WordSpec
    also gets called for the outer
    WordSpecShouldContainerScope
    . What can I use to just have something called for the contained actual tests, i.e. the
    WordSpecTerminalScope
    ?
    s
    15 replies · 2 participants
  • r

    Rob Elliot

    11/29/2021, 10:25 AM
    Do you see any opportunities to speed up running tests via the plugin? I just profiled running a single test in a spec via the green arrow, and it’s taking 5.5 seconds before actually starting the test, mostly in classgraph scanning, which seems unnecessary as the class and test name are being sent to it as
    --spec
    and
    --testpath
    args to
    io.kotest.engine.launcher.MainKt
    in the first place.
    w
    5 replies · 2 participants
  • r

    Rob Elliot

    11/29/2021, 10:51 AM
    Consider editing your IntelliJ Kotest configuration template to add these VM options:
    -Dkotest.framework.classpath.scanning.config.disable=true -Dkotest.framework.classpath.scanning.autoscan.disable=true
    Knocks 5 seconds off running a simple test for me. (obviously if you’re actually relying on automatically discovered kotest config this is not such a great tip…)
    👍🏻 1
    :thank-you: 1
    👍 1
    l
    t
    4 replies · 3 participants
  • s

    Sebastian Schuberth

    11/29/2021, 1:17 PM
    How can I show the exception's message as a clue with
    shouldNotThrowAny
    ?
    s
    3 replies · 2 participants
  • s

    sam

    11/30/2021, 1:02 AM
    Kotest 5.0.1 released
    🎉 1
    🚀 3
    👏 3
    :kotlin-intensifies: 2
    👀 1
    b
    4 replies · 2 participants
  • x

    xenomachina

    11/30/2021, 6:07 PM
    Does 5.0.0 change the order in which tests and/or specs are run? We’re seeing some failures after migrating, and its looking like the issue might be due to this. (Not kotests’s fault, of course. Our tests should be able to run in any order. I’m just curious to know if this is a known change.)
    s
    s
    21 replies · 3 participants
  • r

    rossman

    12/01/2021, 6:46 PM
    Issues with running individual Kotests from IntelliJ in a test class. I setup a new Gradle/Kotlin project in IntelliJ with the Kotest plugin and Kotest 5.0.1 dependencies in the build.gradle. I created a new test class with two tests using StringSpec (I tried FunSpec too). • When I run the test class, both tests run successfully. • When I run the first test, it runs successfully. • When I attempt to run just the 2nd test, I get the message "both tests filtered out" or something like that. I'm kicking off these tests in the IDE using the Kotest plugin panel. Has anyone seen anything like this before? I can provide more details. For now, I've moved on and removed Kotest, and everything is working as expected using pure JUnit5.
    s
    7 replies · 2 participants
  • m

    Mervyn McCreight

    12/03/2021, 12:32 PM
    Hey folks 🙂 Quick question - is there a specific reason why
    eventually
    using kotlins
    Duration
    is still marked with
    @ExperimentalTime
    ? I think since 1.6.0 Duration isn't experimental anymore 🤔
    e
    p
    +1
    5 replies · 4 participants
  • m

    Maxr1998

    12/04/2021, 8:54 PM
    I'm having some issues with the migration, notably with the Koin integration. The KoinExtension registers a
    beforeAny
    that filters
    TestType.Test
    , I previously declared my DI mocks in
    beforeEach
    so that I didn't have to do that extra check. However, with Kotest 5.0,
    beforeEach
    gets called before
    beforeAny
    in TestExtensions, which causes my mocks to fail because Koin hasn't started yet. I wonder if the order in TestExtensions should be changed again, as I'd expect the outer scopes to evaluate before inner scopes, thus container → any → each.
    s
    58 replies · 2 participants
  • m

    Matteo Mirk

    12/06/2021, 9:12 AM
    Is it possible to write a data driven test using StringSpec, wrapping it in a context? So far I’ve only been able to make it work only like this:
    class PriceSpec : StringSpec({
        withData(
            nameFn = { "goods=${it.goods}" },
            // data rows
        ) { (goods, total) ->
            price(goods) shouldBe total
        }
    
        "test incremental" {
            ...
        }
    })
    Originally there were 2 tests, then I transformed the first into a ddt, but I lost its name wrapping the generated cases. I would like to give a name to the ddt, but If I put the withData() declaration inside a string block it’ll fail at runtime, and if I wrap it with a context(“name”) as shown in the docs, only the second test will be executed. What am I doing wrong?
    s
    5 replies · 2 participants
  • s

    Sebastian Schuberth

    12/06/2021, 4:57 PM
    I'm using Kotest's data class matchers to compare two data classes that each contain a field with an instance of a sealed class. While the sealed class instances are different, their data is the same. This makes the test fail. Is this expected? I would have assumed sealed class properties should be compared by their values, just like nested data classes.
    s
    e
    14 replies · 3 participants
  • p

    Philipp Mayer

    12/07/2021, 5:01 PM
    Hello everyone, we currently have all of our tests written with JUnit and kotest assertions. For our e2e tests we wanted to look into Kotest’s behaviour spec as it would improve readability by a big margin. We have the following scenario:
    class SomeE2ETest: E2ETestEnvironment { ... }
    where E2ETestEnvironment is a class (annotated with
    @SpringBootTest
    ) that holds common project config, e.g. a preconfigured http client to post something to the api. Converting this test simply to a Kotest test will not work as we can’t do the following:
    class SomeE2EKotest: E2ETestEnvironment(), BehaviorSpec({ ... })
    because only one class may appear in a super type list. Long story short: I unfortunately couldn’t find any resource about how to do this with Kotest. Our main scenario is that we probably (currently) only translate the E2E Tests, so I’d like to find a way to access the
    E2ETestEnvironment
    from both JUnit tests and Kotest Tests. Thanks in advance!
    s
    e
    +1
    7 replies · 4 participants
  • p

    Peter

    12/09/2021, 6:33 PM
    after upgrading from 4.6.3 to 5.0.1, integration tests are failing when using a postgres testcontainer + listener 🤔
    b
    5 replies · 2 participants
  • s

    sam

    12/10/2021, 12:15 PM
    5.0.2 is out with a bunch of fixes https://kotest.io/docs/changelog.html
    🎉 6
    :kotlin-intensifies: 1
    t
    b
    +1
    32 replies · 4 participants
  • j

    James Eschner

    12/10/2021, 8:39 PM
    Despite potentially looking like a complete buffoon, anyone have ideas about why I can’t seem to get the configuration logging to work correctly? I just bumped to
    5.0.2
    and am set the system property
    kotest.framework.dump.config=true
    in my
    gradle.properties
    but I am not seeing anything in the logs like I used to (prior to the jump to 5+). Is there another way to check the configuration at runtime? * Not a contribution *
    s
    5 replies · 2 participants
  • n

    Niko

    12/17/2021, 8:06 AM
    I'm having issues with the latest versions of Kotest (5.0.2) with IDEA (2021.3) and plugin (1.1.49-IC-213-EAP-SNAPSHOT), and Kotlin 1.6.0: Some time ago, everything was fine and dandy, but then something changed (it was either IDEA update, me changing the project, or upgrading Gradle or Kotlin version changed), and first I started having problems with running individual tests (like Ross wrote earlier). Then, again something changed, and now I'm able to run the tests via IDEA's Run <test class>: <test> gutter icon of individual tests launching the Kotest runner panel, but the Run <test class> now simply launches a Gradle build, no tests run. IDEA's Gradle > project > verification > test runs no tests, nor does running
    ./gradlew test
    . Currently, I have a root project with multiple subprojects (modules), and I'm applying some conventions (like applying Kotest) to all the subprojects using a Gradle plugin. I'm wondering, if this setup has somehow screwed up the discovery (more in thread)
    s
    31 replies · 2 participants
  • l

    LeoColman

    12/17/2021, 3:08 PM
    Did we ever implement those complexity-matchers? I remember we had an idea to have something like
    myAlgo shouldRunIn logOfN()
    🆒 1
    s
    1 reply · 2 participants
  • a

    Asq

    12/20/2021, 11:34 PM
    I have a test that fails because the lhs of
    shouldBe
    is a
    List
    , and the rhs is a home-grown
    Iterable
    . This happens in
    IterablEq.kt
    (kotest 5.0.3) as
    fun isValidIterable(it: Any): Boolean {
          return when (it) {
             is List<*>, is Set<*>, is Array<*>, is Collection<*> -> true
             else -> false
          }
       }
    Could someone please help me understand why a custom implementation of
    Iterable
    should not be considered a valid iterable for the purposes of
    kotest
    ?
    j
    s
    13 replies · 3 participants
  • p

    phil-t

    12/21/2021, 10:56 AM
    I’ve noticed some matcher functions handle nullable variables but other’s don’t e.g. this works for a `String?`:
    testString shouldHaveMinLength 1
    But it doesn’t work for a `Int?`:
    testInt shouldBeGreaterThan 0
    The error is -
    Infix call corresponds to a dot-qualified call 'testInt.shouldBeGreaterThan(0)' which is not allowed on a nullable receiver 'testInt'. Use '?.'-qualified call instead
    So I can get around it by doing this:
    testInt?.shouldBeGreaterThan(0)
    Is this a limitation of Kotest and is there a better way I can handle this?
    s
    3 replies · 2 participants
  • r

    Rob Elliot

    12/21/2021, 7:00 PM
    I'm sure someone has asked this but I can't find it... Just upgraded to 5.0.3 and my tagging strategy to avoid running tests that need to start a docker container seems to no longer work - looks like the tests are skipped, but the listener still starts the container:
    internal class AuctionSniperEndToEndContainerTest : StringSpec({
    
      tags(Docker)
    
      listener(openfireTestContainer(Paths.get("../docker-openfire")).perSpec())
      ...
    }
    s
    27 replies · 2 participants
  • a

    Alexandre Brown

    12/22/2021, 7:41 PM
    Hello, basic question here, I usually use Kotest by initializing my mocks with
    MockkAnnotations.init(this)
    inside the
    beforeEach
    block and I use
    lateinit var
    on my mocks. Is this bad or is this the recommended way? I find that using
    val
    is not always possible as sometimes you have some expectations to setup first.
    class MyClassTest : StringSpec() {
    
    	private lateinit var myClass: MyInterface
    
    	@RelaxedMockK
    	private lateinit var myMock1: MockableThing1
    
    	@RelaxedMockK
    	private lateinit var myMock2: MockableThing2
    
    	init {
    		beforeEach {
    			MockKAnnotations.init(this)
    
    			myClass = MyClass(
    				myMock1,
    				myMock2
    			)
    		}
        }
        ...
    l
    7 replies · 2 participants
  • j

    Javier

    12/24/2021, 5:05 PM
    I checked that property testing is really slow in KMP compared to JVM. Not sure if this is caused by Kotest or just because KMP tests are slow and property testing is running a lot iterations (probably this last one). Any way to improve it? I tried 100k iterations and it was running under 30 secs in jvm, but in other native target is taking over 2 or 3 minutes
    s
    w
    11 replies · 3 participants
  • l

    Lukasz Kalnik

    12/28/2021, 6:14 PM
    How do you assert matchers on nested object contents? Something like capturing slots in MockK. E.g. I have an object like this:
    Success(Either.Left(IOError(cause=com.google.gson.stream.MalformedJsonException)))
    I want to assert certain things: • that the contents of
    Success
    is of type
    Left
    • that the contents of
    Left
    is of type
    IOError
    • that the
    cause
    is of type
    MalformedJsonException
    s
    14 replies · 2 participants
  • s

    Srki Rakic

    01/08/2022, 2:33 PM
    Untitled.kt
    s
    6 replies · 2 participants
  • l

    Lukasz Kalnik

    01/11/2022, 1:10 PM
    I have a test class that looks like this:
    class NetworkEitherCallAdapterTest : StringSpec({
    
      private lateinit var server: MockWebServer
      private lateinit var service: CallErrorTestClient
    
      beforeAny {
          server = MockWebServer()
          server.start()
          service = Retrofit.Builder()
          .baseUrl(server.url("/"))
          .addConverterFactory(GsonConverterFactory.create())
          .addCallAdapterFactory(EitherCallAdapterFactory.create())
          .build()
          .create(CallErrorTestClient::class.java)
      }
      afterAny { server.shutdown() }
    
      "should return ResponseMock for 200 with valid JSON" {
          server.enqueue(MockResponse().setBody("""{"response":"Arrow rocks"}"""))
          val body = service.getEither()
          body shouldBe ResponseMock("Arrow rocks").right()
      }
    
      // More tests...
    I want to run the test class 3 times with different
    service
    instances (which will use different
    ConverterFactory
    each). What is the most readable way to achieve it? I don't want to parameterize every test, I want to parameterize the whole class and repeat it.
    s
    31 replies · 2 participants
  • d

    Dhaval Gondaliya

    01/12/2022, 6:00 AM
    Hello, I am new on Kotest and i read it's intro which says it is testing framework for multi-platform test. So can i use it for android project only? i mean its not multi-platform project.
    w
    m
    +1
    8 replies · 4 participants
  • j

    James Eschner

    01/12/2022, 10:05 PM
    One thing I noticed while creating an
    Arb
    automagically using
    Arb.bind
    is that I’m not getting any null support. For example, if I have the following data class:
    data class Foo(
      val myInt: Int?
    )
    and I generate an arb like so:
    val fooArb = Arb.bind<Foo>()
    I have never encountered a generated value with
    myInt == null
    . Is this expected? Is there a way to get this behavior? * Not a contribution*
    s
    5 replies · 2 participants
  • p

    phldavies

    01/13/2022, 12:34 PM
    Is there a way to assert that a collection contains a single element that satisfies some assertions (rather than a predicate returning boolean?)
    s
    4 replies · 2 participants
Powered by Linen
Title
p

phldavies

01/13/2022, 12:34 PM
Is there a way to assert that a collection contains a single element that satisfies some assertions (rather than a predicate returning boolean?)
i.e. something like
warnings.shouldHaveSingleElementSatisfying {
    message shouldContainIgnoringCase "cheese"
    code shouldBeGreaterThan 100            
}
s

sam

01/13/2022, 12:43 PM
myList.forOne { }
:thank-you: 1
https://kotest.io/docs/assertions/inspectors.html
:nice: 1
p

phldavies

01/13/2022, 12:44 PM
Thanks 🙂 Not sure how I missed that…
View count: 5