https://kotlinlang.org logo
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
benchmarks
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
confetti
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
lincheck
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
Title
t

tim

07/03/2020, 1:41 PM
Ahh ... it looks like when tests are excuted via gradle + cli my custom AbstractProjectConfig isn't being executed ... is that normal behaviour? I had to look at the stack trace to see that my tests were never running due to missing env variables which im currently setting in my PorjectConfig.
s

sam

07/03/2020, 1:48 PM
Should work regardless if its on the classpath
t

tim

07/03/2020, 1:57 PM
I must be missing something 🤔 It works as expected when I run:
gradle :project:test --tests "com.example.MyTest"
but the following fail (because there are no env vars set)
gradle :project:test --tests "com.example.*"
or
gradle :project:test
or
gradle :project:check
??
s

sam

07/03/2020, 1:58 PM
Is the config in the same module as the test
t

tim

07/03/2020, 1:58 PM
yes
s

sam

07/03/2020, 1:58 PM
Is the first one definitely running the test and not skipping it
t

tim

07/03/2020, 1:59 PM
s

sam

07/03/2020, 1:59 PM
Put an init block in your project config and in that init block throw an exception. Then run gradle check and see if it errors out
t

tim

07/03/2020, 1:59 PM
two sec
gradle :cloud:test --tests "io.glimpseprotocol.cloud.SingleVaultTest"
fails when the init block throws
s

sam

07/03/2020, 2:01 PM
Ok I think your error is that you need the use junit block in every gradle file or gradle gets confused
The useJunitPlatform thing
t

tim

07/03/2020, 2:01 PM
ahh
2 sec
doesn't appear to have had any effect
s

sam

07/03/2020, 2:04 PM
I'm pretty sure that's the cause
A test block in every module including root with useJunitPlatform
t

tim

07/03/2020, 2:07 PM
🤷‍♂️
s

sam

07/03/2020, 2:11 PM
Humour me and make the tests block top level in each file
t

tim

07/03/2020, 2:11 PM
👍
No joy 😞
In case it helps here are the two files in question
s

sam

07/03/2020, 2:17 PM
I had this exact error on kotest itself for a while and couldn't figure it out. Then I found that it was because gradle would find no tests (because no test engine was configured) and would report that as an error.
Ahh I have this in kotest as well
filter { isFailOnNoMatchingTests = false }
t

tim

07/03/2020, 2:22 PM
Still failing, but slightly different error message after adding the filter block (top is without the filter block)
Here's the stack trace if thats helpful
s

sam

07/03/2020, 2:24 PM
GLIMPSE_SERVICE_NAME must not be null
t

tim

07/03/2020, 2:27 PM
That value is set inside TestConfig's AbstractProjectConfig block ...
... which brings us back to my initial comment in the main channel 😂
s

sam

07/03/2020, 2:36 PM
lol
well now we've fixed the gradle check thing
can you show me your config class
t

tim

07/03/2020, 2:36 PM
package io.glimpseprotocol.cloud

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.listeners.Listener
import io.kotest.extensions.system.SystemEnvironmentProjectListener

class ProjectConfig : AbstractProjectConfig() {
//    init {
//        error("I'm an error!!!!")
//    }

    override fun listeners(): List<Listener> = listOf(
        SystemEnvironmentProjectListener(
            mapOf(
                "GLIMPSE_ENV" to "test",
                "GLIMPSE_SERVICE_NAME" to "cloud",
                "GLIMPSE_VERSION" to "x.x.x-test",
                "GLIMPSE_PORT" to "20001",
                "GLIMPSE_DOMAIN" to "localhost",
                "GLIMPSE_ROOT_PATH" to "/cloud/v1",
                "GLIMPSE_COOKIE_ENCRYPT" to "covfefeecovfefee",
                "GLIMPSE_COOKIE_SIGN" to "covfefeecovfefee",
                "GLIMPSE_MONGO_URI" to "<mongodb://127.0.0.1:27017/?readPreference=primary&ssl=false>",
                "GLIMPSE_LOGGING_LEVEL" to "debug"
            )
        )
    )
}
s

sam

07/03/2020, 2:40 PM
I think what's happening is the env var is trying to be used before the listeners are firing to set the env vars. Do you have that System.envVar(GLIMPSE_SERVICE_NAME) in a static initializer block
t

tim

07/03/2020, 2:40 PM
i do yes
s

sam

07/03/2020, 2:42 PM
Ok, so gradle will find your test classes first, which causes those init blocks to fire, then passes the classes over to the test engine, in this case kotest
note: static init block is not the same as an init block in a class
t

tim

07/03/2020, 2:42 PM
I assuem you mean something like this:
s

sam

07/03/2020, 2:43 PM
anything in an object will be executed as soon as the class is loaded by the classloader
so way before kotest can get involved
t

tim

07/03/2020, 2:43 PM
makes sense
hmm how to get around 🤔
s

sam

07/03/2020, 2:44 PM
so you could maybe make it lazy
t

tim

07/03/2020, 2:44 PM
could I use lazy?
ya
s

sam

07/03/2020, 2:44 PM
you would need to make the private val lazy
and the object env might need tweaking as well, not sure
t

tim

07/03/2020, 2:47 PM
okay i'll have to play around with this and see if I can get it to work a bit later running out of time before the weekend 🙂 I assume I could just set the env variables inside gradle? Not ideal but could be a workround in the interim. Thank you for your help though 🙏
s

sam

07/03/2020, 2:48 PM
Yes you could do that
and probably is better anyway as env vars ideally should be set before the program starts - setting them in kotest is a bit of a hack as it has to use reflection to change the map
t

tim

07/03/2020, 2:49 PM
I can't recall the reason I put them there, but I just started using kotest like a week ago so 🤷‍♂️
s

sam

07/03/2020, 2:50 PM
There's nothing super bad about it, but I think it's better if it's in the gradle file or whatever.
The kotest env listeners are really intended where you want to tweak an env var while running in order to test that something changes with different values.
t

tim

07/03/2020, 2:58 PM
I prefer them in gradle as well ... they were there a few days ago but I can't recall why I moved them into the test config 🤔
Hey @sam sorry for being a pain. I've tried moving environment variables into build.gradle.kts but now the kotest extension doesn't pickup the variables (iirc this is why I originally used
SystemEnvironmentProjectListener)
. Should kotest be picking up env varialbes from build.gradle.kts? If not, how do people reconcile thier cli test running from the idea test running?
s

sam

07/06/2020, 12:56 PM
kotest picks up env from the shell like any program. My guess is gradle isn't passing them through (forked process?)
t

tim

07/06/2020, 12:59 PM
hmm thats annoying!
i'll take a look at SO and see how striaghtforward it is to expore them into the forked process
thanks!
s

sam

07/06/2020, 1:00 PM
looks like its fairly easy
or you could include them in whatever script you use to start it
t

tim

07/06/2020, 1:01 PM
ahh ya seems striaghtforward