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
strikt
  • r

    robfletcher

    04/22/2020, 8:11 PM
    yeah, that looks like a bug with the implementation of the
    task
    method
    👍 1
    c
    • 2
    • 6
  • c

    cristiangm

    04/24/2020, 8:51 AM
    An idea, for tasks again: I check .is success() but as they have the BuildCache enabled they can be .isFromCache() and I don't like the idea of saying .not().isFailure() ,I wanted to do something like: .any( Success, FromCache) but I don't know how to do it
    r
    • 2
    • 5
  • c

    christophsturm

    05/11/2020, 4:19 PM
    I wonder if
    expectCatching { … }.isA<BlahException>
    should rethrow the exception if its not the expected exception, or at least show the stacktrace of the unexpected exception
    r
    • 2
    • 10
  • r

    robfletcher

    07/15/2020, 8:00 PM
    That looks amazing
    🤗 1
    m
    c
    • 3
    • 10
  • s

    sloydev

    11/26/2020, 10:41 AM
    Hello! I was looking for a way to "group" multiple assertions with a descriptive message, but I did't find an easy (and non-verbose) way to do this in the docs or exploring the API. I implemented something custom, but I wonder if there is a better "native" way. Does anybody know a way to do something like this with the Strikt API?
    expectThat(output) {
      should("Replace anonymous id") {
        get { anonymousId() }.isEqualTo("anonymous_user")
        get { context().traits().anonymousId() }.isEqualTo("anonymous_user")
      }
      should("Remove advertisingId and deviceId") {
        get { advertisingId() }.isNull()
        get { deviceId() }.isNull()
      }
    }
    So I get error messages like these:
    ✗ Replace anonymous id
        ▼ "5c6b6c02-4dd2d":
          ✗ is equal to "anonymous_user"
                  found "5c6b6c02-4dd2d"
        ▼ "5c6b6c02-4dd2d":
          ✗ is equal to "anonymous_user"
                  found "5c6b6c02-4dd2d"
      ✗ Remove advertisingId and deviceId
        ▼ "32c85c4d-c39b897c":
          ✗ is null
        ▼ "c55911907ad":
          ✗ is null
    r
    • 2
    • 9
  • r

    Roukanken

    11/30/2020, 4:47 PM
    Hello! How hard would it be to get Strikt running on Kotlin/JS? As basically only alternative I found for multiplatform that generates such good errors is Atrium - but it's api is ... not that nice There is that one 2 year old issue that says technically it's only a few files that depend on jvm so it shouldn't be that hard I guess? I considered even helping out, but my gradle-fu is too low to convince it to build for multiple platforms...
    r
    c
    • 3
    • 29
  • r

    rocketraman

    11/30/2020, 7:20 PM
    Just checking out Strikt. My previous preferred library was hamkrest. My first assertion is to validate the count of elements in a list. I see
    exactly
    ,
    atMost
    , and
    atLeast
    , but all of these take an additional predicate. Is the preferred approach to do this?
    expectThat(it).get { count() }.isEqualTo(3)
    Is there any particular reason that there isn't a count matcher directly on list?
    r
    • 2
    • 18
  • a

    alorma

    12/02/2020, 3:54 PM
    Hi. I'm having a strange issue with custom strikt exctensions: I have the following extension that checks for params on a
    Intent
    for android:
    inline fun <reified T : Parcelable> Assertion.Builder<Intent>.hasParams(
      paramsName: String,
      noinline block: Assertion.Builder<T>.() -> Unit = {},
    ): Assertion.Builder<Intent> {
      return assert("has params %s", expected = paramsName) {
        val params = it.extras?.getParcelable<T>(paramsName)
        if (params != null) {
          expectThat(params).isA<T>().and(block)
        } else {
          fail()
        }
      }
    }
    When I use this extension, whatever check I put on following lines are marked ass successfull, but those should fail:
    @Test
      fun testHasParamsSuccess() {
        val intent = Intent(getApplicationContext(), SelectCountryActivity::class.java)
          .putExtra("param1", TestClass(id = "ABCD"))
    
        expectThat(intent)
          .hasParams<TestClass>("param1") { get { id }.isEqualTo("ABCD") }
          .assertThat("Simple") { false } // Here assertThat { false } must fail
      }
    What I'm doing wrong with the
    hasParams
    extension?
    r
    • 2
    • 17
  • r

    rocketraman

    01/19/2021, 3:11 PM
    Lets say I have an
    List<Int>
    and I want to check that the first value from the list is less than the second. How can I express this in Strikt?
    expectThat(listOf(5, 6)) {
      // this[1] is a builder, so can't do this:
      this[0].isLessThan(this[1])
    }
    Note because of the way the unit test is structured, I don't actually have access to the original list, only the assertion builder. So I can't just do
    this[0].isLessThan(originalList[1])
    .
    c
    r
    • 3
    • 22
  • c

    christophsturm

    02/01/2021, 12:17 PM
    lets say i have a list of objects and assert on it. if i know all the field values its easy:
    import strikt.api.expectThat
    import strikt.assertions.containsExactly
    
    data class Person(val name: String, val age: Int)
    
    expectThat(listOf(Person("james", 28), Person("jimmy", 28))).containsExactly(
        Person("james", 28), Person("jimmy", 28)
    )
    but what if there is a third field that is random, and that i can’t assert on, what would be the best way to write that in strikt?
    data class Person(val name: String, val age: Int, val weight:Double=Random.nextDouble())
    i want all the elements and the order but not assert on weight.
    r
    • 2
    • 9
  • r

    robfletcher

    02/03/2021, 5:26 PM
    please tell me I don’t have to deal with Nexus repos and their awful UI again
    🖕 1
    👆 1
    a
    • 2
    • 4
  • r

    robfletcher

    02/08/2021, 7:11 PM
    Also 0.29.0 is now out which drops
    strikt-java-time
    in favor of a more general
    strikt-jvm
    . Some of the JVM-specific stuff from
    strikt-core
    also moves to the new module.
    c
    • 2
    • 17
  • a

    alorma

    02/24/2021, 2:42 PM
    Hey. looking at the errors, i thouht.... instead of show this:
    com.infojobs.app.base.datasource.cachedb.DateConverterTest > should convert Instant objects FAILED
        org.opentest4j.AssertionFailedError: ▼ Expect that 2021-02-24T14:04:22.023Z:
          ✗ is equal to 2021-02-24T14:04:22.023564Z
                  found 2021-02-24T14:04:22.023Z
    Wouldn't be better to show like this:
    com.infojobs.app.base.datasource.cachedb.DateConverterTest > should convert Instant objects FAILED
        org.opentest4j.AssertionFailedError:
        ▼ Expect that 2021-02-24T14:04:22.023Z:
          ✗ is equal to 2021-02-24T14:04:22.023564Z
                  found 2021-02-24T14:04:22.023Z
    ????
    r
    c
    • 3
    • 17
  • r

    rocketraman

    03/10/2021, 1:50 PM
    I have a function under test that takes an
    Iterable<T>
    and returns a subset of that given a single element
    T
    . For example, assume my function has signature
    fun <T> Iterable<T>.priorAdjacent(elem: T): List<T>
    . Currently use the pattern:
    expectThat(elems) { get { priorAdjacent(elems[3]) } isEqualTo elems.slice(1..2) }
    which reads nicely and produces understandable failure messages. That being said, is that the best approach?
    r
    c
    • 3
    • 13
  • c

    christophsturm

    03/15/2021, 11:00 AM
    maybe its time for a new strikt release, the main branch has no transitive dependencies on jcenter.
    r
    • 2
    • 3
  • c

    christophsturm

    03/25/2021, 11:10 PM
    there are tests that sometimes very rarely fail and it stays a mystery why they do. i wonder if it makes sense to have support for outputting more diagnostic output in that case
    • 1
    • 4
  • s

    SimonT

    03/28/2021, 7:01 PM
    Hello, is there any way to use coEvery with Strikt? My intento is to verify if a method is called x times and then do an expectThat for another assertions, and I want to get se see everything that fails
    r
    • 2
    • 2
  • c

    christophsturm

    04/07/2021, 10:24 PM
    I wonder if it would be cool to add special handling to isEquals failures that have the same string output.
    r
    • 2
    • 7
  • c

    christophsturm

    04/08/2021, 3:39 PM
    are there matchers for bigdecimal?
    r
    • 2
    • 7
  • c

    christophsturm

    04/16/2021, 10:57 AM
    what do you think about something like
    val parsed=expectThat("""{"abc":"def"}""").isValidJsonFor<MyType>()
    👎 1
    r
    • 2
    • 5
  • d

    dave08

    04/26/2021, 11:20 AM
    I little point I got caught with a few times... using
    and { get(SomeClass::someProp).isEqualTo(...) }
    on a nullable type without
    isNotNull()
    allows the
    and
    , but has
    get()
    undefined... I wonder if it makes sense to have an
    and
    in this case in the first place...? What can one do with a nullable type? Also, is there anything like a
    isNotNullAnd { ... }
    or
    withNotNull { }
    ? I find myself doing
    expectThat(result).isNotNull().and { ... }
    quite often...
    c
    r
    • 3
    • 43
  • d

    dave08

    04/29/2021, 10:13 AM
    It seems like the
    Result
    assertions don't all work anymore... they complain that
    Result<T>
    can't be cast to
    T
    ... maybe the fact that my
    T
    is nullable is the cause?
    c
    r
    • 3
    • 38
  • d

    dave08

    05/02/2021, 2:08 PM
    Trying to write matchers for https://github.com/michaelbull/kotlin-result, but I'm having a bit of trouble understanding how to return things... I have:
    fun <V, E> Assertion.Builder<Result<V, E>>.isFailure(): Assertion.Builder<E> =
        assert("is failure") {
            when {
                it is Err -> pass(
                    description = "threw %s",
                    actual = it.error
                )
                else -> fail(
                    description = "returned %s",
                    actual = it.get()
                )
            }
        }
            .get("exception") {
                unwrapError()
            }
    
    fun <V, E> Assertion.Builder<Result<V, E>>.isSuccess(): Assertion.Builder<V> =
        assert("is success") {
            when {
                it is Ok -> pass()
                else -> fail(
                    description = "was error ${it.unwrapError()}",
                )
            }
        }
            .get("value") {
                unwrap()
            }
    
    inline fun <reified E> Assertion.Builder<Result<Any?, E>>.failedWith() =
        isFailure().isA<E>()
    But when I try `
    expectThat(result).isFailure().isA<SomeDomainError>()
    I get:
    org.opentest4j.AssertionFailedError: ▼ Expect that Ok(SomeStub(id=1,...)):
      ✗ is failure
        returned SomeStub(id=1, ...)
    r
    • 2
    • 7
  • d

    dave08

    05/02/2021, 3:15 PM
    Ok, I got it partially:
    inline fun <V, reified E> Assertion.Builder<Result<V, E>>.isFailureOf(): Assertion.Builder<E> =
        assert("is failure of type ${E::class.simpleName}") {
            when {
                it is Err -> pass(
                    description = "threw %s",
                    actual = it.error
                )
                else -> fail(
                    description = "returned %s",
                    actual = it.get()
                )
            }
        }
            .get("exception") {
                unwrapError()
            }
    But still won't give me the actual
    E
    I want only the base class of it. Ideally I'd like to provide one type param, and have it report that name in the assert... but it seems like Kotlin won't let me use * for the
    V
    in
    Result
    ...
    s
    • 2
    • 2
  • d

    dave08

    05/12/2021, 9:34 AM
    Using
    first { }
    is a bit not fitting for Strikt's usually explicit and nice exceptions:
    Mapping 'first matching element %s' failed with: Collection contains no element matching the predicate.
    ???
    c
    • 2
    • 2
  • r

    robfletcher

    05/23/2021, 3:27 PM
    This is the issue blocking me on upgrading Strikt to Kotlin 1.5 (I don’t think it will bite you using existing Strikt releases with 1.5 unless you use
    Assertion.Builder<Result<*>>
    ) https://youtrack.jetbrains.com/issue/KT-46890
    d
    • 2
    • 13
  • c

    christophsturm

    08/25/2021, 7:54 AM
    so what about that strikt release, can i somehow help to get it released?
    r
    • 2
    • 1
  • r

    rocketraman

    08/25/2021, 4:36 PM
    I'm testing a function with signature
    fun <T: Comparable<T>> ClosedRange<T>.intersects(other: ClosedRange<T>): Boolean
    . My test has inputs (note there is a fake failure case here,
    0..0
    is not intersecting):
    val intRangeRef = 1..5
    val intRangesIntersecting = listOf(0..0, 0..2, 4..5, 4..6)
    val intRangesDisjoint = listOf(-2..-1, 6..7)
    How would you structure the assertions? So far I've got this, which produces nice output on failures, but thoughts on style?
    expectThat(intRangesIntersecting).all {
      get { intRangeRef.intersects(this) } isEqualTo true
      get { this.intersects(intRangeRef) } isEqualTo true
    }
    expectThat(intRangesDisjoint).all {
      get { intRangeRef.intersects(this) } isEqualTo false
      get { this.intersects(intRangeRef) } isEqualTo false
    }
    r
    • 2
    • 11
  • c

    christophsturm

    09/08/2021, 9:25 AM
    what about making single, get, first, etc available on nullable subjects?
    r
    • 2
    • 2
  • g

    Gustavo Torrecilla

    09/17/2021, 7:27 PM
    Hi everyone, I saw strikt on Github and I love it. Can you help me with this 2 questions 1- Is the current version of skirt (0.32.0) stable or is a beta? 2- Are you planning to make mayor changes in the public API in the near future?
    r
    • 2
    • 1
Powered by Linen
Title
g

Gustavo Torrecilla

09/17/2021, 7:27 PM
Hi everyone, I saw strikt on Github and I love it. Can you help me with this 2 questions 1- Is the current version of skirt (0.32.0) stable or is a beta? 2- Are you planning to make mayor changes in the public API in the near future?
r

robfletcher

09/17/2021, 7:37 PM
• 0.32.0 is the latest and is stable, I guess 😬 • no big plans to make API changes in the near future, no
👍 1
View count: 7