https://kotlinlang.org logo
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
spek
  • d

    dmcg

    03/28/2019, 4:23 PM
    @svenjacobs I usually just use lazy vals for things like that
    s
    • 2
    • 1
  • m

    mgrzechocinski

    04/02/2019, 3:10 PM
    Yeah, also interested about that. In my case I want to start IoC container and stop it once tests are done
    r
    • 2
    • 1
  • a

    Abbas A

    04/03/2019, 10:25 AM
    Hi, could someone explain why
    beforeGroup
    is executed only once even if test has more then one group on one level? And if so, how do you work with this?
    t
    r
    • 3
    • 12
  • s

    Shan

    04/06/2019, 6:46 PM
    Has anyone encountered any issues with Spek2 and kotlin multiplatform project? Spek2 can't seem to find any of my tests when I use the
    src > commonMain, commonTest, jvmMain, jvmTest
    format (I'm only trying to run the tests with jvmTest source set)
    t
    • 2
    • 3
  • s

    Shan

    04/07/2019, 7:38 PM
    Here's the full stacktrace. Using version 2.0.1, when I run the
    jvmTest
    task in a Kotlin MP project
    -.lua
    r
    • 2
    • 11
  • j

    JoakimForslund

    04/09/2019, 2:51 PM
    Is it possible to run commonTest without jvm involved at all in a multiplatform test-setup of spek currently?
    r
    • 2
    • 2
  • d

    dewildte

    04/13/2019, 12:51 AM
    The one in intelliJ is awesome for a basic HTML report. But I was wondering if there is more people suggest.
    r
    • 2
    • 1
  • m

    martin.petrulak

    04/15/2019, 9:26 PM
    @dewildte you can use jacoco
    s
    • 2
    • 3
  • r

    ragunathjawahar

    05/02/2019, 2:28 AM
    Hello, I am trying out Spek 2 with Truth. I have a passing test despite a failing assertion. I tried running the tests from Gradle, it still passes. Can someone help?
    CanaryTest.kt
    package dev.ragunath.spek2
    
    import com.google.common.truth.Truth.assertThat
    import org.spekframework.spek2.Spek
    import org.spekframework.spek2.style.specification.describe
    
    class CanaryTest : Spek({
      describe("A test environment") {
        it("is ready to run tests") {
          assertThat("a").isEqualTo("b") // <- Failing assertion.
        }
      }
    })
    Also, here is my
    build.gradle
    .
    plugins {
      id 'org.jetbrains.kotlin.jvm' version '1.3.31'
    }
    
    group 'dev.ragunath'
    version '0.1.0-SNAPSHOT'
    
    repositories {
      mavenCentral()
      jcenter()
    }
    
    dependencies {
      implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
      implementation 'io.arrow-kt:arrow-core-data:0.9.0'
    
      // Spek
      testImplementation 'org.spekframework.spek2:spek-dsl-jvm:2.0.3'
      testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:2.0.3"
      testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:1.3.31"
    
      // Truth
      testImplementation 'com.google.truth:truth:0.44'
    }
    
    compileKotlin {
      kotlinOptions.jvmTarget = '1.8'
    }
    
    compileTestKotlin {
      kotlinOptions.jvmTarget = '1.8'
    }
    r
    • 2
    • 5
  • s

    svenjacobs

    05/08/2019, 12:08 PM
    Hi, since Spek 2.0.3 test scope builders come with a default timeout of 10 seconds. Is it possible to globally change the default timeout value w/o having to apply a custom timeout to every test?
    r
    • 2
    • 3
  • s

    svenjacobs

    05/08/2019, 12:13 PM
    Also I noticed that since upgrading to Spek 2.0.3 the amount of test results drastically reduced in Jenkins from 1000 to a few hundreds. After upgrading to 2.0.4 even less tests are reported. Did something change how Spek reports JUnit test results?
    r
    t
    • 3
    • 19
  • r

    robstoll

    05/15/2019, 7:30 PM
    @raniejade I might update to spek2 and require the
    include
    from 1.x, can you give me a pointer how I should implement it in 2.x and would you be interested in a pull request?
    r
    • 2
    • 1
  • r

    robstoll

    05/16/2019, 5:48 AM
    What is the status of MPP? is it possible to write a spek test in a common module and run it for a jvm module?
    r
    • 2
    • 3
  • r

    robstoll

    05/18/2019, 6:35 PM
    as far as I can see
    action
    is no longer available in 2.x what is now the idiomatic way of writing dependent tests? Following an example how I used it in spek 1.x:
    action("calling peek for the first time") {
        val obj = object : Any() {}
        val itr = listOf(obj).iterator().toPeekingIterator()
        val result = itr.peek()
        it("returns the element") {
            assert(result).isSameAs(obj)
        }
        it("calling it a second time still returns the same element") {
            val result2 = itr.peek()
            assert(result2).isSameAs(obj)
        }
        it("calling hasNext returns true") {
            assert(itr.hasNext()).toBe(true)
        }
        it("calling next returns the same element") {
            assert(itr.next()).isSameAs(obj)
        }
        it("calling then hasNext returns false") {
            assert(itr.hasNext()).toBe(false)
        }
    }
    r
    • 2
    • 4
  • t

    tapchicoma

    05/27/2019, 7:54 AM
    changelog for
    2.0.5
    release is missing
    r
    • 2
    • 2
  • t

    tapchicoma

    05/30/2019, 10:01 AM
    Idea 2019.1.3 and spek 2.0.5: When I try to run single spek test from IDE - it always fails with "Test framework quit unexpectedly". How to fix it or should I open new issue for it?
    r
    • 2
    • 4
  • t

    Trevor Ackerman

    06/24/2019, 7:01 PM
    Is there any way with Spek to add categories for tests? Specifically looking for for something to allow having a gradle task that runs long running tests and let the default gradle test task only execute fast unit tests.
    t
    • 2
    • 4
  • j

    JoakimForslund

    07/24/2019, 2:15 PM
    So I managed to get spek to run with multiplatform + android target which is awesome! But, the error message which it gives when something fails:
    org.host.class.someSpek > Settings randomId = 1234567 FAILED
        org.junit.ComparisonFailure at spektest.kt:21
    Is a bit lack luster, I'd want it to type out the expected value. Is there any way to do that?
    r
    r
    • 3
    • 6
  • r

    robstoll

    07/25/2019, 7:25 PM
    Any plans to release a spek plugin for intellij 2019.2? The current does not seem to be compatible
    r
    • 2
    • 2
  • v

    v79

    08/11/2019, 8:05 AM
    In a framework like Spek, are all mocks (e.g. with mockk) initialized all at once, on start up? I would have hoped that mocks were scoped to their corresponding
    describe
    or
    it
    blocks. As it is, even if I run a single
    it
    block test in Intellij, all the mocks across all blocks are being initialized. Is this a consequence of putting the entire test suite into the constructor of my test class (which seems bonkers to me)?
    r
    m
    • 3
    • 3
  • b

    Big Chungus

    09/25/2019, 10:50 AM
    What assertion framework are you guys using with spek?
    r
    m
    +2
    • 5
    • 5
  • b

    Big Chungus

    09/25/2019, 10:52 AM
    Also, can i use this to write tests for my common module?
    r
    • 2
    • 1
  • b

    Big Chungus

    09/26/2019, 5:59 AM
    Because beforeGroup is executed before the entire FeatureSet
    r
    • 2
    • 4
  • s

    Shan

    12/03/2019, 1:11 AM
    Anyone know how I can debug the
    Test framework quit unexpectedly
    error I am getting when trying to run a test? Can't seem to find any error statements anywhere. Using v2.0.8 with an Android module, junit5 plugin is applied, have all the dependencies added correctly. 🤔
    r
    • 2
    • 3
  • e

    edwinRNDR

    12/10/2019, 7:58 PM
    I am using spek 2.0.9 to test OpenGL (lwjgl) based code. I run in to the problem that tests are executed on another thread (that doesn't have an OpenGL context associated). How do I tell Spek to run tests on the main thread?
    r
    • 2
    • 1
  • f

    Franz See

    01/01/2020, 8:20 AM
    I am using Spek2 which spawns an embedded server (running on a different thread). I want this server to be up and running while executing all tests but shut down after finishing all tests. Normally (in junit 5 or testng), i would do something like this when i create the server.
    fun getOrCreateServer() {
        ...
        Runtime.getRuntime().addShutdownHook(Thread(Runnable {
            server.shutdown();
        }))
        return server
    }
    Then in my tests, I would just call this method to get the server instance and do stuff with it. Then after all tests have executed, this would be called to shutdown the server In Spek2, this does not get called How do I what I want to do in Spek2? 🙂
    r
    • 2
    • 4
  • c

    codeslubber

    01/06/2020, 11:57 PM
    I found an article on medium about setting up Spek2 and thought I’d give it another look. The steps all worked, but you have to run the tests by right clicking on the folder. Is there no runner? that would make it possible to run tests from within the source?
    r
    • 2
    • 35
  • s

    Shan

    01/26/2020, 9:33 PM
    I see in the older Spek (1) docs that Spek does not support Android integration tests. Is this the case for Spek2 as well?
    r
    • 2
    • 1
  • l

    lucasqueiroz

    02/06/2020, 3:19 PM
    Hey guys, it's been probably asked before and I'm sure I've done this before, but I can't really find it anymore :/ how do I write tests where I need to have a @Autowired dependency? Thanks
    👀 1
    r
    • 2
    • 4
  • j

    jk2018

    02/15/2020, 4:44 AM
    Hey, I'm trying to set up for an Android project, following this https://www.spekframework.org/setup-android/ , but I would like to use KTS / build.gradle.kts files. It's basically working, but I can't figure out how to config the part "
    testLogging.events = ["passed", "skipped", "failed"]
    in Kotlin KTS.. Anyone got a hint?
    r
    t
    • 3
    • 26
Powered by Linen
Title
j

jk2018

02/15/2020, 4:44 AM
Hey, I'm trying to set up for an Android project, following this https://www.spekframework.org/setup-android/ , but I would like to use KTS / build.gradle.kts files. It's basically working, but I can't figure out how to config the part "
testLogging.events = ["passed", "skipped", "failed"]
in Kotlin KTS.. Anyone got a hint?
r

raniejade

02/15/2020, 6:17 AM
What does your build file look like? Kotlin does not have a list literal, so you have to use
listOf(..)
.
j

jk2018

02/15/2020, 6:26 PM
here's what it looks like:
import de.mannodermaus.gradle.plugins.junit5.junitPlatform
plugins {
id("com.android.library")
id("de.mannodermaus.android-junit5")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
}
android {
compileSdkVersion(SdkVersions.compile_sdk_version)
defaultConfig {
versionCode = AppVersions.versionCode
versionName = AppVersions.versionName
minSdkVersion(SdkVersions.minSdkVersion)
targetSdkVersion( SdkVersions.targetSdkVersion)
testInstrumentationRunner = Dependencies.android_test_runner
testInstrumentationRunnerArgument("runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder")
dataBinding {
isEnabled = true
}
lintOptions {
isAbortOnError = false
}
}
androidExtensions {
isExperimental = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "<http://proguard-rules.pro|proguard-rules.pro>")
}
}
sourceSets.getByName("main") {
java.srcDir("src/main/java")
java.srcDir("src/main/kotlin")
}
sourceSets.getByName("test") {
java.srcDir("src/test/java")
java.srcDir("src/test/kotlin")
}
//==================
testOptions {
junitPlatform {
filters {
includeEngines("spek2")
}
jacocoOptions {
// here goes all jacoco config, for example
html.enabled = true
xml.enabled = false
csv.enabled = false
}
}
}
}
the jacocoOptions part converted fine from groovy , but I can't seem to find how do migrate the testLogging.events = ["passed", "skipped", "failed"] part
( I'm trying to convert https://github.com/spekframework/spek/blob/2.x/samples/android/app/build.gradle to kts)
r

raniejade

02/15/2020, 10:47 PM
What errors are you getting? Conversion should look like:
unitTests.all {
    testLogging.events = listOf("passed", "skipped", "failed")
}
j

jk2018

02/16/2020, 12:13 AM
The error was that it wasn't able to create Groovy closure from Kotlin. Similar to Example 25 in this doc: https://docs.gradle.org/current/userguide/kotlin_dsl.html
I got what I wanted by doing this:
tasks.withType<Test> {
        testLogging { 
            events("passed", "skipped", "failed")
        }
    }
unitTests.all expects a Groovy closure:
public void all(final Closure<Test> configClosure) {
r

raniejade

02/16/2020, 12:16 AM
Ahh nice. Have you tried upgrading the android-junit 5 plugin? I'm pretty sure the example is using a very old version that might not be compatible with kotlin-dsl
j

jk2018

02/16/2020, 12:17 AM
i could not figure out how to get that Groovy closure from a
KotlinClosure1
it compiles, but failes with "value is null" very strange..
upgrading junit5 ? how?
r

raniejade

02/16/2020, 12:18 AM
not junit5 itself but
android-junit5
, versions are defined here: https://github.com/spekframework/spek/blob/2.x/samples/android/gradle.properties
https://github.com/mannodermaus/android-junit5
j

jk2018

02/16/2020, 12:26 AM
Just updated, still seems to be the same if I'm not totally confused now
r

raniejade

02/16/2020, 12:29 AM
Sucks, just go with what you have previously then 🙂
j

jk2018

02/16/2020, 12:30 AM
yup, that's what I got 🙂
gradle+groovy can be such a nightmare sometimes
➕ 1
r

raniejade

02/16/2020, 12:31 AM
Indeed 🙂
j

jk2018

02/16/2020, 12:33 AM
thx for your response!
t

tapchicoma

02/16/2020, 9:50 PM
KotlinDSL has
closureOf<T> {}
method that you could use in this case: https://gradle.github.io/kotlin-dsl-docs/api/org.gradle.kotlin.dsl/kotlin.-any/closure-of.html
j

jk2018

03/02/2020, 5:48 PM
I tried that one and that didn't work. Did you try it?
t

tapchicoma

03/02/2020, 8:05 PM
yes, worked for me 🤔 You need to do
unitTests.all(closureOf { ... })
View count: 9