https://kotlinlang.org
Join Slack
Hi all! I am using mockk for tests but keeps failing to mock the calls that I expect, when I try run...
v

vio

over 4 years ago
Hi all! I am using mockk for tests but keeps failing to mock the calls that I expect, when I try running all tests from cli (with gradle:
gradle :test
). when run individually with
kotest
runs perfectly. I have something like this:
beforeSpec {
  Application.start()
  mockkObject(MyObjectClass)
  every { MyObjectClass.getRandomString() } returns "call made"
})

afterSpec {
   clearAllMocks()
   Application.stop()
}

....
// some other tests that should make calls to the function that I mocked above

"verify mockk" {
   verify(exactly = 7) {
        MyObjectClass.getRandomString()
   }
}
I can't figure out what could be wrong here, I get this error when run from the command line :
java.lang.AssertionError: Verification failed: call 1 of 1: MyObjectClass(object MyObjectClass).getRandomString()) was not called  .......
Any help is appreciated, thank you! 🙏
v
m
s
  • 3
  • 10
  • 508
Hi, I'm trying to mock a static method that takes a `() -> Unit` function as a parameter, but the...
y

Yeray Cabello

about 6 years ago
Hi, I'm trying to mock a static method that takes a
() -> Unit
function as a parameter, but the matchers seem not to be able to get the mocking signature:
io.mockk.MockKException: Failed matching mocking signature for

left matchers: [any()]
What am I missing? I know that equality with lambdas can be a nightmare, but can't seem to find documentation on this.
Untitled.kt
y
  • 1
  • 2
  • 508
Can anyone explain what is by activityViewModels(), by fragmentViewModels(), by existingViewModels()...
i

Ive Vasiljevic

over 6 years ago
Can anyone explain what is by activityViewModels(), by fragmentViewModels(), by existingViewModels() and so on used for. I get the idea that by activityVideModels() is used for shared viewModels between mutliple fragments that need to use data from the same viewModel, but how does it work..Do I actually need to extend activity with that viewModel or what? Do I need to specifiy viewModel factory or not?
i
l
  • 2
  • 2
  • 508
Does compose multiplatform now support obfuscation with proguard? I think I remember reading that th...
d

Dan River

about 2 years ago
Does compose multiplatform now support obfuscation with proguard? I think I remember reading that there were problems.
d
z
e
  • 3
  • 5
  • 505
`java.lang.ClassCastException: kotlin.Unit cannot be cast to kotlin.Result` when using `useIR = true...
a

Arpan Sarkar

over 4 years ago
java.lang.ClassCastException: kotlin.Unit cannot be cast to kotlin.Result
when using
useIR = true
Kotlin Version : 1.4.32 After upgrading to 1.4.32 all
runCatching { }
call are throwing
java.lang.ClassCastException
is there any bug or breaking changes in version 1.4.32 ? As an example
suspend fun connect(clientId: String): Boolean {
        if (isConnected) {
            Timber.d("Already connected to broker ${mqttClient.serverURI}")
            return true
        }
        mqttClient = MqttClient(BuildConfig.BROKER_URI, clientId, null)
        mqttClient.setCallback(mqttCallback)

        val result = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            runCatching {
                Timber.d("Connecting to broker  ${mqttClient.serverURI}")
                val options = MqttConnectOptions().apply {
                    mqttVersion = MqttConnectOptions.MQTT_VERSION_3_1_1
                    isCleanSession = true
                    isAutomaticReconnect = true
                    maxReconnectDelay = 10000
                }
                mqttClient.connect(options)
                Timber.d("Broker connected.")
            }
        }
        result.exceptionOrNull()?.let { t ->
            Timber.e(t, "Failed to connect to the broker.")
        }
        return result.isSuccess
    }
a
r
  • 2
  • 1
  • 505
Hi, I'm working through the Ktor documentation and example Task API and curiously tried to use the j...
p

Paul at Avans Breda

over 1 year ago
Hi, I'm working through the Ktor documentation and example Task API and curiously tried to use the just announced Ktor 3.0.0-beta-2. I get the following error when at section: https://ktor.io/docs/3.0.0-beta-1/server-create-restful-apis.html#create-unit-tests Execution failed for task ':compileTestKotlin'.
Could not resolve all files for configuration ':testCompileClasspath'.
> Could not find io.ktorktor server test base3.0.0-beta-2. Searched in the following locations: - https://repo.maven.apache.org/maven2/io/ktor/ktor-server-test-base/3.0.0-beta-2/ktor-server-test-base-3.0.0-beta-2.pom Required by: project : > io.ktorktor server tests jvm3.0.0-beta-2 Possible solution: - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html Any suggestions? Thanks!
p
a
  • 2
  • 6
  • 504
How can i save a `ImageBitmap` to a file and later share that file in KMP?
v

Vaibhav Jaiswal

over 1 year ago
How can i save a
ImageBitmap
to a file and later share that file in KMP?
v
a
  • 2
  • 4
  • 504
Hey everyone I am running into this error when setting up `androidx` UI testing with compose in my ...
s

Sher Sanginov

almost 4 years ago
Hey everyone I am running into this error when setting up
androidx
UI testing with compose in my project. Any idea what may be wrong? I tried to play with dependencies but no success.
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.myapp.debug.test/androidx.activity.ComponentActivity }
	at androidx.test.core.app.InstrumentationActivityInvoker.startActivity(InstrumentationActivityInvoker.java:387)
 ...
Full stacktrace in thread.
s
a
  • 2
  • 4
  • 504
Hi, how can I do Koin injection in iOS side? Tried <https://medium.com/@uwaisalqadri/elegant-koin-in...
h

Hasan Nagizade

over 2 years ago
Hi, how can I do Koin injection in iOS side? Tried https://medium.com/@uwaisalqadri/elegant-koin-injection-for-swift-in-kotlin-multiplatform-mobile-9a803f6efb2e and https://github.com/Kashif-E/KmMScientists/blob/master/iosApp/iosApp/Di/KoinModule.swift both of them work fine but I would love to learn the best practise.
h
s
k
  • 3
  • 4
  • 503
does compose multiplatform has Videoplayer?
a

Abdullah

almost 2 years ago
does compose multiplatform has Videoplayer?
a
j
m
  • 3
  • 7
  • 502
Previous128129130Next

kotlinlang

A modern programming language that makes developers happier.

Powered by