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
kotlintest
  • u

    Uzi Landsmann

    05/21/2019, 10:50 AM
    Kotlintest documentation ells me to use the following in my kotlin gradle build:
    val test by tasks.getting(Test::class) {
        useJUnitPlatform { }
    }
    However, it is apparently marked unstable. Is there a way around this?
    p
    • 2
    • 3
  • c

    codyoss

    06/07/2019, 2:33 PM
    I am having issues using breakpoint in IntelliJ integration tests /w kotlintest. My app is written with springboot and I am using the
    SpringListener
    stuff. The app is also built on coroutines, and I am trying to put a breakpoint in a suspend function. Is there a known issue around my use case that anyone has heard of? To be clear my test does work when I just run it, and I am able to put breakpoints in the non-coroutine parts of my code.
    l
    • 2
    • 8
  • h

    Hexa

    06/19/2019, 7:52 AM
    I tried this and it didn't work. the doc is not very clear on how to use this projectconfig properly and there are many examples around
    import io.kotlintest.AbstractProjectConfig
    import io.kotlintest.IsolationMode
    
    object ProjectConfig : AbstractProjectConfig() {
        fun isolationMode(): IsolationMode = IsolationMode.InstancePerTest
    
        private var started: Long = 0
    
        override fun beforeAll() {
            started = System.currentTimeMillis()
        }
    
        override fun afterAll() {
            val time = System.currentTimeMillis() - started
            println("overall time [ms]: " + time)
        }
    }
    t
    s
    • 3
    • 74
  • l

    LeoColman

    06/19/2019, 5:06 PM
    Do you believe we should discuss this library you posted here?
    b
    m
    • 3
    • 5
  • a

    Abbas A

    06/22/2019, 4:11 PM
    looking in codebase we see that it should be called: https://github.com/kotlintest/kotlintest/blob/8c695c95338f5222378e1c3b7fbd6ece5ed776fa/kotlintest-core/src/main/kotlin/io/kotlintest/Project.kt#L94
    • 1
    • 1
  • s

    sam

    06/22/2019, 6:17 PM
    You have a
    TestListener
    and you've overriden the
    beforeTest
    function ?
    a
    • 2
    • 14
  • s

    sam

    06/29/2019, 6:45 AM
    KotlinTest 3.3.3 has been released.
    🎉 4
    m
    • 2
    • 2
  • b

    bbaldino

    07/17/2019, 8:19 PM
    working on trying to isolate it down now
    s
    w
    • 3
    • 62
  • t

    tseisel

    07/18/2019, 9:51 AM
    How should I use the
    infix fun <T> T.should(matcher: (T) -> Unit)
    ? What's its purpose ? I use it like this :
    person.should {
        it.firstName shouldBe "John"
        it.lastName shouldBe "Doe"
    }
    But that
    should
    seems redondant to me.
    w
    l
    • 3
    • 4
  • s

    sam

    07/22/2019, 3:38 PM
    https://github.com/thewhitespace/Spoke
    d
    m
    • 3
    • 7
  • l

    LeoColman

    07/22/2019, 3:58 PM
    I've never seen github down
    m
    • 2
    • 3
  • d

    Dias

    07/23/2019, 9:27 AM
    I understand there is no way to run just a particular test in the spec?
    m
    l
    s
    • 4
    • 12
  • t

    thanksforallthefish

    07/24/2019, 9:11 AM
    is there an alternative way to support spring constructor injection than https://github.com/kotlintest/kotlintest/blob/master/doc/extensions.md#constructor-injection ? The problem I am facing is that I have a class that works with
    org.springframework.context.ApplicationEventPublisher
    and I cannot unit test it. What I mean is, if I write a test like
    class SomeTest(
      private val applicationEventPublisher: ApplicationEventPublisher = mockk(relaxed = true),
      private val myClass: MyClass(applicationEventPublisher)) : StringSpec() {...}
    applicationEventPublisher
    visible to the test is not the mocked one but the one instantiated from
    ProjectConfig
    . A workaround is to have
    class SomeTest : StringSpec() {
      private val applicationEventPublisher: ApplicationEventPublisher = mockk(relaxed = true),
      private val myClass: MyClass(applicationEventPublisher)
    ...
    }
    so actually not a big deal
    • 1
    • 1
  • t

    thanksforallthefish

    07/24/2019, 11:22 AM
    I actually like the 2 source sets approach, at some point I will migrate tests. thanks for the feedback
    m
    • 2
    • 1
  • d

    Dias

    07/25/2019, 10:31 AM
    When I setup a spec, if I use lambda instead of init to place my tests into, that means I cannot really afterTest/beforeTest referencing stuff inside of that lambda. So if I want to reset a mock for example after each test, I need to use init {} way of writing tests or do resetting in the body of each test?
    a
    l
    s
    • 4
    • 4
  • s

    sam

    08/13/2019, 12:42 AM
    I'd like to start some documentation on why KotlinTest is a better choice than JUnit
    m
    • 2
    • 12
  • l

    LeoColman

    08/13/2019, 1:25 AM
    This can be done in JUnit through
    @Before
    , but it's only for all test cases. Many times you have nested setups that will use the same input, but you'll have to repeat them over and over when using JUnit
    m
    • 2
    • 1
  • l

    LeoColman

    08/13/2019, 3:36 AM
    With our Listeners, it's very easy to setup code to be used only by certain classes
    m
    • 2
    • 3
  • s

    sam

    08/24/2019, 9:31 PM
    Or maybe some way to override
    w
    • 2
    • 1
  • t

    thuytrinh

    08/31/2019, 1:39 PM
    Hi all. I’m wondering whether there’s a plugin to run each individual test on IDE? I hope there’s something similar to https://spekframework.org/running/#ide. I’ve tried https://plugins.jetbrains.com/plugin/11585-kotlintest. However, whenever I run a single test by clicking on the green play button, the IDE run the entire tests. Also, when I right click on each test on the Test Results tree of the Run window, it shows
    Nothing here
    menu pop. Not sure if this is a bug.
    • 1
    • 1
  • s

    sam

    08/31/2019, 2:14 PM
    Make sure when you click the individual arrows you have deleted any configs for the double arrow
    👍 1
    t
    • 2
    • 2
  • b

    bbaldino

    09/05/2019, 6:22 PM
    trying it out but running into a dep thing...i just need to depend on hoplite-core and, say, hoplite-json, is that right?
    s
    • 2
    • 15
  • j

    Johan Alkstål

    09/08/2019, 7:15 AM
    Hi! I am learning Kotlin and I've never worked with the Java platform before, so I am as noob as they come in that regard. I've made a unit test with Kotlintest but when I run it it seems Gradle doesn't find the test?
    Execution failed for task ':test'.
    > No tests found for given includes: [com.projectfaceoff.rink.entities.EntityManagerTest](filter.includeTestsMatching)
    I'm sure I've missed something in the setup or something or placed the test file in the wrong place, KotlinTest docs don't say much about those things expect how to config the gradle build file. I have a class extended with
    BehaviorSpec
    inside a
    test/kotlin/com.foo.bar/
    folder and created a
    Given
    When
    Then
    test.
    u
    s
    • 3
    • 49
  • s

    Sergio Crespo Toubes

    09/10/2019, 2:48 PM
    Hello, can someone help me? How can i test method like this?
    fun loadData() = MainScope().launch {
    
    }
    d
    • 2
    • 2
  • s

    sam

    09/10/2019, 6:19 PM
    there should be one in io.kotlintest.properties or something like that
    j
    • 2
    • 12
  • b

    bbaldino

    09/10/2019, 7:31 PM
    @sam would you be opposed to a PR for hoplite which allowed for comments in json? there's an option in jackson.
    s
    • 2
    • 47
  • b

    bbaldino

    09/10/2019, 8:43 PM
    @sam i'm also finding that params marked with JsonProperty don't seem to map correctly, or at least not all of them? i have a test case here that repros it: https://github.com/bbaldino/hoplite/blob/json_property/hoplite-json/src/test/kotlin/com/sksamuel/hoplite/json/JsonPropertyTest.kt
    • 1
    • 3
  • s

    sam

    09/12/2019, 2:31 PM
    Why not make login user an extension on CoroutineScope then you can call it on a main scope as well as just call it inside a kotlintest test
    s
    • 2
    • 2
  • s

    Stian N

    09/19/2019, 10:39 AM
    Any input on how we can solve this? https://stackoverflow.com/questions/57972025/kotlintest-how-to-use-abstract-testcontainers-class
    t
    l
    +2
    • 5
    • 8
  • l

    leodeleon

    09/24/2019, 3:10 PM
    Can I use kotlintest for Espresso tests? Is there any good sample code?
    w
    l
    • 3
    • 20
Powered by Linen
Title
l

leodeleon

09/24/2019, 3:10 PM
Can I use kotlintest for Espresso tests? Is there any good sample code?
w

wasyl

09/24/2019, 3:42 PM
Afaik you can’t. Since Espresso (as well as Robolectric) use a JUnit4 runner, you can’t use them with KotlinTest which is based on JUnit5
https://github.com/kotlintest/kotlintest/issues/189
l

LeoColman

09/24/2019, 7:15 PM
Yes you can.
I've been testing with Espresso and Robolectric
Roboletric isn't rady yet, but espresso tests need no additional setup as far as I've tested
😲 1
w

wasyl

09/24/2019, 7:16 PM
What’s the difference? Don’t both instrumented tests and Robolectric tests use the same runner?
Is there any sample/documentation yet?
l

LeoColman

09/24/2019, 7:18 PM
No
Robolectric has it's own runner
But Android runs on JUnit
There is no official documentation, but I'm tinkering with my personal project and this will be in KotlinTest for 4.0
https://github.com/Kerooker/rpg-npc-generator/blob/feature/17-random-npc-screen/app/src/androidTest/java/me/kerooker/rpgnpcgenerator/view/RandomNpcFragmentTest.kt
Example class for Espresso test
In the same app there is a very alpha version of the Robolectric runner that we have been building
w

wasyl

09/24/2019, 7:35 PM
Is there no additional configuration there? 😮 It just has
androidx.test.runner.AndroidJUnitRunner
configured in the manifest and that’s it?
this will be in KotlinTest for 4.0
So it doesn’t work in 3.x yet? Can you tell me what was the required change(s) to make it work?
l

LeoColman

09/24/2019, 7:37 PM
It does work
I really didn't do any change... It was actually funny, I was experimenting on what I needed to do for UI testing and... It was already done
It uses the default AndroidJUnitRunner which delegates to JUnit. The KotlinTest JUnit5 runner works
Robolectric requires configuration tho
But be careful. We are not completely sure on how everything works, so treat everything as experimental
👍 1
View count: 2