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
mockk
  • d

    dave08

    12/26/2018, 2:53 PM
    Am I doing this right? The
    download
    function seems to return, but before, it should return progress through the
    SendChannel
    (coroutines) passed to it... will that code do this?
    o
    • 2
    • 5
  • h

    Hadi Tok

    12/26/2018, 3:47 PM
    I had a problem with mockk on gradle 5.0 . it is about ByteBuddyAgent dependency scope I think. Is it a known problem or should I create an issue for this?
    o
    • 2
    • 7
  • d

    dave08

    01/03/2019, 12:46 PM
    How do I mock a public field in a Java class with a package local constructor, I need to pass it to another class's constructor...?
    h
    • 2
    • 2
  • t

    tKw

    01/07/2019, 2:30 PM
    @oleksiyp, I may have missed this in the documentation, but are there any rules or best practices around when to use
    answers
    over
    returns
    ?
    o
    • 2
    • 3
  • w

    Willis

    01/07/2019, 11:20 PM
    Anyone here used mockK to test their common code in #multiplatform project? I’m having an
    Unresolved reference: mockK
    error when I execute the test
    • 1
    • 1
  • t

    tKw

    01/08/2019, 1:28 AM
    Is it possible to verify code within a lambda is ran? With the following code:
    fun getAllActiveWidgetsByPrice(db: DatabaseConnection): List<Widgets> = db.query {
        Widgets.select {
            Widgets.active eq true
        }.orderBy(Widget.price).map { toWidget(it) }
    }
    Could we verify that
    Widgets.select
    is called? Could we verify that we pass a lambda with
    Widgets.active eq true
    to
    Widgets.select
    ? I feel like there is a way to do this, but I have not been able to get it to work.
    h
    • 2
    • 1
  • h

    Hadi Tok

    01/08/2019, 7:52 AM
    @oleksiyp I want to contribute to the library but I don't know where to start. if you can give me some pointers I can try to help.
    o
    • 2
    • 33
  • c

    Chris Margonis

    01/08/2019, 3:23 PM
    Hi folks, thanks for the awesome library 💪 I have a question, is it possible to mock a constructor invocation and thus return a mock? Something similar to powermock’s
    PowerMockito.whenNew(RandomClass.class).withAnyArguments().thenReturn(myMock)
    • 1
    • 1
  • h

    Hadi Tok

    01/11/2019, 7:32 AM
    I am getting
    io.mockk.MockKException: Missing calls inside every { ... } block.
    while trying to mock staticString. is it a known problem?
    -.java
    o
    • 2
    • 2
  • s

    Slackbot

    01/14/2019, 7:14 PM
    This message was deleted.
    t
    s
    • 3
    • 2
  • a

    Anthony f

    01/17/2019, 3:22 PM
    Here is the test template, that I try to run.
    -.kt
    o
    • 2
    • 8
  • o

    oleksiyp

    01/18/2019, 2:18 PM
    Can you please report same to GH issue
    👍 1
    t
    • 2
    • 4
  • l

    LeoColman

    01/19/2019, 4:47 PM
    Hey, @oleksiyp. I see that
    ExpectSpec
    is being used here. Please let us know if you believe that this is #kotlintest's fault 🙂
    o
    • 2
    • 2
  • d

    dave08

    01/21/2019, 3:40 PM
    Is it possible to mock a Java static function, there doesn't seem to be any mention of this in the docs?
    o
    • 2
    • 7
  • a

    Anthony f

    01/21/2019, 5:07 PM
    Does one you already succeed to mock Build.VERSION.SDK_INT ?
    t
    • 2
    • 5
  • s

    Saiedmomen

    01/25/2019, 5:35 PM
    Hi guys. I trying to mock a method that returns coroutine
    Job
    But I get this runtime exception
    java.lang.IllegalArgumentException: proxied interface methods have incompatible >return types:
    public abstract boolean kotlinx.coroutines.Job.cancel()
    public abstract void kotlinx.coroutines.Job.cancel()
    at java.lang.reflect.Proxy.validateReturnTypes(Proxy.java:328)
    o
    • 2
    • 6
  • a

    Anthony f

    01/30/2019, 10:42 AM
    Does confirmVerified works with Static mock ? I get “io.mockk.MockKException: can’t find stub class” exception when using it
    o
    • 2
    • 4
  • g

    groostav

    01/31/2019, 11:01 PM
    hey so, I started using mockk and I got some really strange behaviour that simply comes from mockito-like stack-index-checking. Can I ask you guys why you went with mockito style DSL when kotlin has such nice method references? Using kotlin method references, you can ditch all of the scary not-thread-safe parameter/argument capturing in mockito and provide a pretty slick DSL:
    fun usage(){
        val result2 = buildMock<java.lang.ProcessBuilder>{
            ProcessBuilder::inheritIO {
                TODO()
            }
    
            //one problem with method refs is that they are ambiguous when the method is overloaded
            // but inference takes care of that reasonably elegently
            oneArg(ProcessBuilder::directory).invokes {
                TODO()
            }
        }
    I also think that using kotlin property references could make mocking of properties much nicer
    o
    • 2
    • 1
  • s

    svenjacobs

    02/07/2019, 11:22 AM
    Hi all, quick question: With MockK, how do I verify that a specific function of a mock was never called?
    verify {
      mock.myFunction(any()) wasNot called
    }
    Doesn't seem to be correct as this is always true, regardless of whether the function was called or not.
    o
    • 2
    • 5
  • s

    svenjacobs

    02/08/2019, 12:01 PM
    I have another question 😉 Why is that
    coEvery { view.showDeleteSectionDialog() } returns true
    produces
    Bad recording sequence. State: AnsweringState
    but
    with(view) {
        coEvery { showDeleteSectionDialog() } returns true
    }
    does not?
    o
    • 2
    • 22
  • j

    Joram Visser

    02/16/2019, 7:09 PM
    Is it possible to mock a suspend inline extension function? If so, how?
    o
    l
    • 3
    • 5
  • h

    Hadi Tok

    02/18/2019, 4:07 PM
    -.kt
    o
    k
    • 3
    • 7
  • s

    Sergio Crespo Toubes

    02/22/2019, 9:32 AM
    How can i reset the verify count?
    verify(exactly = 1) { mView.showLocations(any()) }
    
    // Reset verify
    
    locationListPresenter.onFilterTextChanged(text)
    verify(exactly = 1) { mView.showLocations(any()) }
    i am with this isolationMode
    IsolationMode.InstancePerLeaf
    o
    • 2
    • 2
  • d

    Davide Giuseppe Farella

    02/28/2019, 7:26 AM
    How to properly
    mockk / verify
    a lambda? Looks like
    val observer = mockk<(Int) -> Unit>() 
    observer( 1) 
    verify { observer( 1 ) }
    Is not working. Tbh I didn't test exactly that code, I was trying within an Android LiveData, but replacing the mockk with a real lambda i can see right output printed in the console. Same with
    spy
    o
    • 2
    • 6
  • a

    Anthony f

    03/07/2019, 5:28 PM
    hello guys, I try to mock/verify String.format(....)
    o
    l
    t
    • 4
    • 25
  • h

    Hexa

    03/16/2019, 8:40 PM
    the
    GlobalScope.async { "testCarId" }
    part seems weird to me I tried
    returns  "testCarId"
    but I'm getting an incompatible type error
    o
    • 2
    • 10
  • h

    Hexa

    03/17/2019, 10:39 AM
    it looks like it doesnt matter what I use as my tests passed on either of them. But I would like to know if I'm verifying the coroutine properly
    o
    • 2
    • 4
  • d

    darych

    03/19/2019, 1:10 PM
    Hi all! Could somebody please explain what this error means?
    io.mockk.MockKException: Failed matching mocking signature for\n\nleft matchers: [any(), any(), any()]
    Version 1.8.9 Code:
    every { clientFactory.invoke(any(), any(), any()) } returns client
    clientFactory
    is factory function which returns the object of client.
    l
    • 2
    • 12
  • h

    Hexa

    03/29/2019, 11:55 PM
    I need some advice, I have lot of tests that uses
    any()
    as argument in the
    every
    part of my tests and then in the
    verify
    part I checked the exactly value of the argument like this
    every { car.drive(any()) } returns Outcome.OK
    
    verify(exactly = 1) {
        car.drive(Direction.SOUTH)
    }
    . I did this because it saves me a lot of typing (and maybe it makes the code more readable as it's shorter) when the argument I'm passing is too long for example: https://gist.github.com/rinnegan/bd8928a750fab4eaebf89652972c7647#file-using-any-L16. So it is okay to write my tests like this? Or do I need to avoid using
    any()
    and be very explicit and specify the exact argument?
    l
    d
    • 3
    • 11
  • n

    Nav Singh

    04/03/2019, 3:19 PM
    anyone provide any assistance on this
    l
    • 2
    • 11
Powered by Linen
Title
n

Nav Singh

04/03/2019, 3:19 PM
anyone provide any assistance on this
l

LeoColman

04/03/2019, 3:32 PM
Could you show us a code snippet?
I've never had any problems with Mockk + Lateinit properties
n

Nav Singh

04/03/2019, 5:11 PM
yes
fun gotoEmailConfirmation(update: Boolean){ view.gotoEmailConfirmation(update,email) }
email filed is private lateinit var in class
private lateinit var email : String
it's passed to function as a parm
@LeoColman
l

LeoColman

04/03/2019, 5:16 PM
Could you please give me some more details? Maybe create a very simple and complete class, and show me a test for it?
n

Nav Singh

04/03/2019, 6:35 PM
ok
I ll catch you latr
View count: 12