You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kotlinFixture { ... } returns a com.appmattus.kotlinfixture.Fixture. The Fixture class and its configuration is immutable and stateless by nature.
As a function you'd need to call it as myReusableFixture()(). However, there's nothing stopping you storing your shared configuration in a top-level val:
privateval myReusableFixture = kotlinFixture { property(X::y) { y } }
Regardless of whether this is a fun or val you will always get different values back when calling myReusableFixture<Type>() as it is random by nature.
To mitigate this the easiest suggestion for when you need to refer to one of the values is to create the needed instance outside of your mock, so something like this:
@Test
funmyTest {
// Ifalotofyourtestsaregeneratingthesamefixturethiscouldbegeneratedasaclassmemberinsteadvaloutcome = myReusableFixture<Outcome>()
val car = mockk<Car>()
every { car.drive(Direction.NORTH) } returns outcome
...
}
Hello, I tried to return a kotlinFixture in a function with ConfigurationBuilder, but I discovered that I have no idea what type it will return.
Is there any way to return the correct type for
private fun myReusableFixture(): Sometype = kotlinFixture { property(X::y) { y } }
It will complain when used as fun fixture() = myReusableFixture() and then fixture() in the every mockk.
I want to return the same fake values in multiple tests, now it generates a new fake value that I have no reference to.
The text was updated successfully, but these errors were encountered: