lupuuss / mokkery Goto Github PK
View Code? Open in Web Editor NEWThe mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.
Home Page: https://mokkery.dev
License: Apache License 2.0
The mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.
Home Page: https://mokkery.dev
License: Apache License 2.0
It seems that using value class, e.g. kotlin.Result
in mocks will fail the test with exception
Given the interface
interface TestInterfaceWithValueClass {
fun test(): Result<String>
}
Calling the test
@Test
fun testReturnsMockableInterfaceWithValueClassImpl() {
val mocked = mock<TestInterfaceWithValueClass> {
every { test() } returns Result.success("test")
}
assertEquals(Result.success("test"), mocked.test())
}
Will fail with exception
java.lang.NullPointerException: Cannot invoke "kotlin.Result.unbox-impl()" because the return value of "dev.mokkery.internal.MokkeryInterceptor.interceptCall(dev.mokkery.internal.CallContext)" is null
at dev.mokkery.test.TestInterfaceWithValueClassb7d4c11efdfd4d2aa2c67574e6dd5d5eMock.test-d1pmJ48(MockTest.kt)
at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1$1.invoke-IoAF18A(MockTest.kt:23)
at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1$1.invoke(MockTest.kt)
at dev.mokkery.internal.EveryKt.internalEvery(Every.kt:21)
at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1.invoke(MockTest.kt)
at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1.invoke(MockTest.kt:22)
at dev.mokkery.test.TestInterfaceWithValueClassb7d4c11efdfd4d2aa2c67574e6dd5d5eMock.<init>(MockTest.kt)
at dev.mokkery.test.MockTest.testReturnsMockableInterfaceWithValueClassImpl(MockTest.kt:22)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
...
mokkery version: 1.9.23-1.6.0
kotlin version: 1.9.23
Currently, Mokkery requires abstract
/open
classes to have a default constructor, and it should be possible to remove this requirement.
This limitation was partially mentioned in #4 .
I have the implementation of this data class:
@Serializable
data class WordPair(
val wordsTotal: Int,
val wordsFound: List<String>
)
at first run, I get this error:
Type ''com.alejandrorios.bogglemultiplatform.data.models.WordPair'' is final and cannot be used with ''mock''!
which I know it is because of one of the limitations of the library, then I'm including the @OpenForMokkery
annotation to the data class, and now I get this error:
Class ''com.alejandrorios.bogglemultiplatform.data.models.WordPair'' has no default constructor and cannot be used with ''mock''!
Is it possible to solve this without adding default values to the data class?, maybe I'm missing something else.
Hey team Mokkery,
This is more of an information request than an issue, just wondering, if and when we can expect support for Kotlin 2.0?
I'm aware it's still in beta, but we'd love to start testing it asap, but since mokkery is a crucial part of the application we're a bit blocked.
Best,
-martin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.