570 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
Best practices
0
votes
2
replies
49
views
Kotlin - Mocking object with Scanner dependency
I have just started with Kotlin, so I'm not sure what the best practices are. The object file looks like this at the moment, as I am expecting the user's input:
object FlowCoordinatorUtil {
private ...
-1
votes
1
answer
113
views
Mockk Static persists behavior across tests
I have mocked a class as follows:
@Before
fun setup() {
mockkStatic(MyUtils::class)
}
@After
fun tearDown() {
clearStaticMockk(MyUtils::class)
}
Then i define behavior of MyUtil's ...
1
vote
1
answer
84
views
Why can't mockk verify that my Micronaut meter counter got incremented?
I want to test that some code updates Micronaut (4.7.5) metrics. (In real life, the code under test gets passed the MeterRegistry and calls its methods.)
import io.micrometer.core.instrument.Counter
...
2
votes
1
answer
210
views
Why is CoroutineContext element null via kotlin.coroutines.coroutineContext in tests (Kotest/Dispatchers.Default) but not production?
I'm encountering a discrepancy in retrieving a custom CoroutineContext.Element (TraceContextElement) depending on the environment (test vs. production) and how I access the context within a launched ...
0
votes
1
answer
77
views
mockk/spyk on WebView in instrumented tests
My app uses Jetpack Compose and includes a WebView.
I want to use Mockk (or something like that) in instrumented tests,
for example, I want my tests to check that
WHEN webView.canGoBack() THEN the ...
2
votes
1
answer
146
views
mockk Unit Test - Missing mocked calls inside every {} block [closed]
I see a few posts about this issue, but I still can't resolve this. Can somebody explain why this unit test doesn't work any longer? I've made changes to by build.gradle file, but still no luck.
@Test
...
0
votes
2
answers
46
views
How to test that exception been thrown in Mockk
I need to verify that exception been thrown or that some logging method been called.
Here is my code
fun stop() {
println("----")
CoroutineScope(Dispatchers.IO).launch {
try {...
0
votes
0
answers
48
views
ClassCastException when attempting to access Result.Success(Object) value in a Test
I have a unit test that mocks a service with mockk and returns a Result.Success(value) instance when a certain function is called. The problem is that when I go to access the value in the result ...
0
votes
1
answer
109
views
How to automatically apply SINGLE custom JUnit5 extension to all test classes?
I have a custom junit5 extension, that purpose is to do some clean up after each test class.
I want it to be applied to all test classes in multi-module project automatically.
Problem is when I enable ...
1
vote
1
answer
115
views
How to fix this ClassCastException in UnitTest
I'm currently facing some problems while adding UnitTests to my JetPack Compose Project.
I want to test the following (a bit shortened) function in my viewmodel:
fun onPressSignUp() {
...
1
vote
1
answer
212
views
Unit Tests with Mockk library fails on CI but works everytime in local
Hi I have some unit tests for my multi-modular Android Project and I want to run a CI pipeline with these tests but as the header says some tests that are using mockk to mocking operations are failing ...
0
votes
0
answers
123
views
Mock ktor client `HttpRequestBuilder.() -> Unit` with Mockk
I tried to mock the Ktor HttpClient.post(url, HttpRequestBuilder.() -> Unit) in my tests like this.
@Test
fun `submit report`() = runTest {
val mockHttpClient: HttpClient = mockk()
val ...
0
votes
1
answer
147
views
Override a composable in androidTest
I've got a layout hierarchy, that looks like (from top to bottom):
SearchResultScreen
ProductGridView
———————————————— all composables below are handled by a different team
CustomProductTile
...
1
vote
0
answers
150
views
How to unit test the suspend function to meet branch coverage using mockk
I wrote a Kotlin code and I want to write unit tests for it. But I found that the unit test code I wrote still cannot cover 100% branch coverage. What should I do it?
kotlin code:
class MyRepository @...
1
vote
0
answers
129
views
How to test if spy init block calls a method using Mockk
Libraries
testImplementation("io.mockk:mockk:1.13.12")
val junitVintageVersion = "5.10.3"
testImplementation("org.junit.vintage:junit-vintage-engine:$...