Jonathan Lennox
05/31/2022, 7:07 PMGopal S Akshintala
06/04/2022, 1:46 PMinit {}
block of companion object?Iwan Aucamp
06/10/2022, 2:21 PM2022-06-10 16:05:52,447 ERROR [io.qua.test] (Test runner thread) Test EventServiceTest failed
: java.lang.NoSuchMethodError: com.google.cloud.pubsub.v1.Publisher: method 'void <init>()' not found
at com.google.cloud.pubsub.v1.PubSubProviders_ProducerMethod_publisher_d487368ec6013065bb45001d5339f823b74b492b_ClientProxy.<init>(Unknown Source)
at no.coop.sapcrm.profile.events.PubSubProviders_ProducerMethod_publisher_d487368ec6013065bb45001d5339f823b74b492b_Bean.proxy(Unknown Source)
at no.coop.sapcrm.profile.events.PubSubProviders_ProducerMethod_publisher_d487368ec6013065bb45001d5339f823b74b492b_Bean.get(Unknown Source)
at no.coop.sapcrm.profile.events.PubSubProviders_ProducerMethod_publisher_d487368ec6013065bb45001d5339f823b74b492b_Bean.get(Unknown Source)
at io.quarkus.arc.impl.InstanceImpl.getBeanInstance(InstanceImpl.java:223)
at io.quarkus.arc.impl.InstanceImpl.getInternal(InstanceImpl.java:209)
at io.quarkus.arc.impl.InstanceImpl.get(InstanceImpl.java:95)
at io.quarkus.test.junit.QuarkusMock.installMockForType(QuarkusMock.java:57)
at no.coop.sapcrm.profile.events.EventServiceTest.setupMocks(EventServiceTest.kt:40)
Helio
06/16/2022, 4:42 AMmockk
? During the migration our team noticed that some of our Integration tests were breaking because mockk
is no longer able to mock Ktor HttpClients.
Does anyone knows anything about that? I read through the Ktor migration guided but I could not find any behaviour change.
For example: The snippet below used to work with Ktor v1, but it is no longer working with Ktor v2.
myHttpClient = mockk<MyHttpClient>()
mockkObject(MyHttpClient)
coEvery { MyHttpClient.getClient() } returns myHttpClient
Any tip would be greatly appreciated.Vivek Modi
06/19/2022, 11:47 AMinternal fun setupExploreConsultationVisibility(hasFocus: Boolean) {
if (hasFocus) {
.....
} else if (viewModel.queryText.isEmpty()) {
binding.consultationViewSwitcher.displayConsultationViewSwitcherChild(0)
}
}
internal fun ViewSwitcher.displayConsultationViewSwitcherChild(childNumber: Int) {
visible()
displayedChild = childNumber
}
eygraber
06/30/2022, 8:49 PMMattia Tommasone
07/06/2022, 2:00 PMMikhail
07/15/2022, 7:13 PMdata class Bean(val message: String = "hello")
val mock = mockk<Bean>(relaxed = true)
mock.message // "hello" ?
Mikhail
07/15/2022, 7:37 PMcapture(...)
as a parameter for extension functions?
e.g.
val slot = slot<String>()
capture(slot).snakeCase()
Ondřej Šimon
07/20/2022, 6:37 AMjava.lang.InstantiationError: com.ColorRepository
at jdk.internal.reflect.GeneratedSerializationConstructorAccessor7.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48)
at io.mockk.proxy.jvm.ObjenesisInstantiator.instanceViaObjenesis(ObjenesisInstantiator.kt:75)
at io.mockk.proxy.jvm.ObjenesisInstantiator.instance(ObjenesisInstantiator.kt:42)
at io.mockk.impl.instantiation.JvmInstantiator$instantiate$2.invoke(JvmInstantiator.kt:16)
at io.mockk.impl.instantiation.AbstractInstantiator.instantiateViaInstanceFactoryRegistry(AbstractInstantiator.kt:17)
at io.mockk.impl.instantiation.JvmInstantiator.instantiate(JvmInstantiator.kt:15)
at io.mockk.impl.recording.states.RecordingState$matcher$signatureValue$1$1.invoke(RecordingState.kt:49)
at io.mockk.impl.instantiation.JvmAnyValueGenerator$anyValue$2.invoke(JvmAnyValueGenerator.kt:35)
at io.mockk.impl.instantiation.AnyValueGenerator.anyValue(AnyValueGenerator.kt:34)
at io.mockk.impl.instantiation.JvmAnyValueGenerator.anyValue(JvmAnyValueGenerator.kt:31)
at io.mockk.impl.recording.states.RecordingState$matcher$signatureValue$1.invoke(RecordingState.kt:48)
at io.mockk.impl.recording.JvmSignatureValueGenerator.signatureValue(JvmSignatureValueGenerator.kt:20)
at io.mockk.impl.recording.states.RecordingState.matcher(RecordingState.kt:47)
at io.mockk.impl.recording.CommonCallRecorder.matcher(CommonCallRecorder.kt:52)
at com.ColorSynchronizationServiceTest$testSynchronizeFromErp - new sync manager instance is created and its method called$1.invoke(ColorSynchronizationServiceTest.kt:67)
at com.ColorSynchronizationServiceTest$testSynchronizeFromErp - new sync manager instance is created and its method called$1.invoke(ColorSynchronizationServiceTest.kt:41)
at io.mockk.impl.eval.RecordedBlockEvaluator$record$block$1.invoke(RecordedBlockEvaluator.kt:25)
at io.mockk.impl.eval.RecordedBlockEvaluator$enhanceWithRethrow$1.invoke(RecordedBlockEvaluator.kt:78)
at io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:23)
at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:40)
at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
at io.mockk.MockKDsl.internalEvery(API.kt:93)
at io.mockk.MockKKt.every(MockK.kt:98)
at com.ColorSynchronizationServiceTest.testSynchronizeFromErp - new sync manager instance is created and its method called(ColorSynchronizationServiceTest.kt:41)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
The test looks like the following:
@Test
fun `testSynchronizeFromErp - new sync manager instance is created and its method called`() {
val improvedErpSynchronisationManagerMock =
mockk<ImprovedErpSynchronisationManager<ColorErpDto, Color, ColorRepository>>()
every {
improvedErpSynchronizationManagerFactoryServiceMock
.constructImprovedErpSynchronisationManager<ColorErpDto, Color, ColorRepository>(
any(),
any(),
any(),
)
} returns improvedErpSynchronisationManagerMock
every { improvedErpSynchronisationManagerMock.executeDataSynchronisationFromErp() } returns Unit
colorSynchronizationService.synchronizeFromErp()
verifySequence {
improvedErpSynchronizationManagerFactoryServiceMock.constructImprovedErpSynchronisationManager<ColorErpDto, Color, ColorRepository>(
any(),
any(),
any()
)
}
}
and the mocked generic method looks like the following:
@Service
class ImprovedErpSynchronizationManagerFactoryService(
private val platformTransactionManager: PlatformTransactionManager
) {
fun <D : ErpDto, E : ErpEntity, R : ErpSynchronizableRepository<E>> constructImprovedErpSynchronisationManager(
processedEntityType: Class<E>,
repository: R,
improvedErpDataLoaderAndTransformer: ImprovedErpDataLoaderAndTransformer<D, E>
): ImprovedErpSynchronisationManager<D, E, R> {
return ImprovedErpSynchronisationManager<D, E, R>(
processedEntityType,
repository,
improvedErpDataLoaderAndTransformer,
TransactionTemplate(platformTransactionManager)
)
}
}
I have been lost on this for a few days now and I have no idea how to fix this error. Do you have any hints?Adam S
07/21/2022, 4:55 PMExecution failed for task ':mockk-common:test'.
> No tests found for given includes: [io.mockk.it.ValueClassTest](--tests filter)
I'm not sure how to proceed because I want to debug through the code, but I don't want to set a breakpoint and skip every single other test. Are there any tricks I'm missing for setting up the mockk project locally?cymessmer
07/24/2022, 10:16 AMbbaldino
07/25/2022, 6:25 PMcoEvery { myClass.myMethod(any(), any()) } returns myFakeResponse()
and i'm hitting:
java.lang.NullPointerException
at io.mockk.impl.recording.states.RecordingState.matcher(RecordingState.kt:53)
at io.mockk.impl.recording.CommonCallRecorder.matcher(CommonCallRecorder.kt:52)
has anyone run into this before?Mattia Tommasone
07/27/2022, 3:58 PMAdam Pelsoczi
07/28/2022, 8:10 AMRuntimeException
when unit tests execute any code which has a public static function written in a java class file (Log.d
, ParcelUuid.fromString
, Instant.of
)
Method d in android.util.Log not mocked. See <http://g.co/androidstudio/not-mocked> for details.
java.lang.RuntimeException: Method d in android.util.Log not mocked. See <http://g.co/androidstudio/not-mocked> for details.
https://gist.github.com/apelsoczi/497a8f002d78da0bb5121b94755b868c
Here's a gist of two files. Within the CoroutineUseCaseTest
there is a ExceptionUseCase
which extends UseCase
and invoking Log.d(TAG, "invoke: ", e)
causes the above error. I am baffled at why what is documented to mock a static java method is not working.
Every post I read online says to mockStatic(
) and write every {}
in an @Before
annotated method.Teimatini Marin
07/29/2022, 4:24 PMoverride suspend fun read(channel: Channel<String>) {
val req = GetObjectRequest {
bucket = "localbucket"
key = "part2.csv"
}
s3.getObject(req) { resp ->
val stream = resp.body as ByteStream.OneShotStream
val flow = produceFlow(stream.readFrom())
consumeFlow(flow, channel)
}
}
where getObject is defined as
suspend fun <T> getObject(input: GetObjectRequest, block: suspend (GetObjectResponse) -> T): T
Teimatini Marin
07/29/2022, 4:27 PMMichael de Kaste
08/11/2022, 8:28 AMMattia Tommasone
08/22/2022, 8:43 PMigor.wojda
08/30/2022, 1:52 PMclass ExampleUnitTest {
private val repository = mockk<AlbumRepository>()
private val cut = GetAlbumUseCase(repository)
@Test
fun `when execute return success`() {
// given
val albumName = "Thriller"
val artistName = "Michael Jackson"
val mbId = "123"
// when
val actual = runBlocking { cut.execute(albumName, artistName, mbId) }
// then
}
}
no answer found for: AlbumRepository(#1).getAlbumInfo(Thriller, Michael Jackson, 123, continuation {})
io.mockk.MockKException: no answer found for: AlbumRepository(#1).getAlbumInfo(Thriller, Michael Jackson, 123, continuation {})
at app//io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:93)
The answer can't be found (most likely due to continuation {}
param).
I have crafted a sample project to reproduce this. Steps:
1. Open project using Android Studio
2. Run ExampleUnitTest
tests
Can someone take a look? Is there any workaround?MSC
09/14/2022, 9:31 PMmockkStatic
? I'm having issues when running tests in parallel due to mocking using mockkStatic
The only way I've managed to make it work was with @Isolated
annotation at the top of each test class.
TIAGasan
09/19/2022, 12:02 PMGasan
09/19/2022, 12:21 PMwhen(service.method()).thenReturn("bar")
analog in mockk?Matteo Mirk
09/20/2022, 9:12 AMmockkConstructor()
on the superclass and then stub with anyConstructed()
, but it didn’t work.
Is this even possible to achieve with Mockk? The docs don’t say anything about this scenario.Nikunj Yadav
09/21/2022, 6:34 PMMichael de Kaste
09/28/2022, 12:25 PMvars
work automatically on a mockk?
Having to specify
every{ someClass.someValue = any() } answers { every { someClass.someValue } returns firstArg() }
for every field is a hasslethanksforallthefish
09/29/2022, 8:05 AMMikhail Fedotov
10/04/2022, 7:02 AMverify { getAllMocks() wasNot called }
Klitos Kyriacou
10/06/2022, 10:03 PMevery { ... } returns ...
, or justRun {...}
calls. Is there a way to turn on some diagnostic that tells you about any calls to every
or justRun
that weren't followed by an actual call to the given mock method?Lukasz Kalnik
10/10/2022, 11:30 AM