Shalom Halbert
12/13/2020, 7:01 PMtieskedh
12/15/2020, 2:34 PMopen class FlatmapCombinedShrinker2<Original, value1, value2>(
private val select1: (Original) -> value1,
private val shrinker1: Shrinker<value1>,
private val select2: (Original) -> value2,
private val shrinker2: Shrinker<value2>,
private val composer: Original.(value1, value2) -> Original
) : Shrinker<Original> {
override fun shrink(value: Original): List<Original> {
val hasShrinks = BooleanArray(2) { true }
val value1 = select1(value)
val shrinks1 = shrinker1.shrink(value1).ifEmpty {
hasShrinks[0] = false
listOf(value1)
}
val value2 = select2(value)
val shrinks2 = shrinker2.shrink(value2).ifEmpty {
hasShrinks[1] = false
listOf(value2)
}
return if (hasShrinks.any { it }) {
shrinks1.flatMap { val1 ->
shrinks2.map { val2 ->
value.composer(val1, val2)
}
}
} else emptyList()
}
}
Mervyn McCreight
12/15/2020, 3:52 PMproperty-based-testing
in Kotest. I want to create a custom arbitrary
based on already defined arbitraries
. I found this page in the documentation about it:
https://kotest.io/docs/proptest/custom-generators.html#arbitrary
In the documentation there is a code snippet about doing it:
val personArb = arbitrary { rs ->
val names = Arb.string().values(rs)
val ages = <http://Arb.int|Arb.int>().values(rs)
names.zip(ages).map { (name, age) -> Person(name.value, age.value) }
}
The concept is clear, but the function values(RandomSource)
is deprecated. What am I supposed to use as an alternative in this case? Would it be generate(RandomSource)
? The replacement description is not really applicable for this particular case I think. Using samples(RandomSource)
seems wrong, because I think it makes sense to keep the edge-cases of the arbs here 🤔 .bbaldino
12/16/2020, 12:21 AM4.3.1
, and notice that when running tests in maven and one fails, I only get the string from the bottom-most should
in the report, which makes it ambiguous. Is there a way to get the entire test "path" string to show up there? I.e. the stuff from the surrounding context
blocks?bbaldino
12/16/2020, 11:09 PMrunBlockingTest
and advanceUntilIdle
and I think it's fooling kotest into thinking the test has timed outdave08
12/17/2020, 11:37 AMchristophsturm
12/17/2020, 12:07 PMShalom Halbert
12/17/2020, 1:20 PMdave08
12/20/2020, 2:05 PMsam
12/21/2020, 11:00 PMkopper
12/22/2020, 8:31 AMkotest.proptest.default.iteration.count
to something low, e.g. 1
, plenty of my tests fails because computeDefaultIteration
provides 1
for arbs with edgecases where minIterations > 1
. Is this a bug or there's logic behind this? Right now computeDefaultIteration
explicitly supports only Exhaustive
https://github.com/kotest/kotest/blob/master/kotest-property/src/commonMain/kotlin/io/kotest/property/config.kt#L17kopper
12/22/2020, 8:47 AMminIterations
for Arb
include at least one sample? Right now it counts only all edge cases https://github.com/kotest/kotest/blob/master/kotest-property/src/commonMain/kotlin/io/kotest/property/Gen.kt#L39Joel Hess
12/31/2020, 7:41 PM@SpringBootTest
annotation, can I get access to the app context within a specific test? I’m trying to migrate some tests that look like this:
contextRunner.run { context ->
assertThat(context)
.hasSingleBean(MongoCustomConversions::class.java)
}
and change properties on the context for a test?
contextRunner
.withPropertyValues("spring.data.mongodb.migrations.enabled:false")
.run { context ->
assertThat(context)
.doesNotHaveBean(Mongobee::class.java)
}
sam
01/06/2021, 7:18 PMnelson ramirez
01/08/2021, 3:12 AMArb.bind()
, the object contains a list of other objects. I'm having trouble generating a list of objects to populate my main arb with..
Here's what I have
class CartModelTest : StringSpec({
"create Cart from CartEntity" {
val cartItemArb: Arb<CartLineItemEntity> = Arb.bind(
Arb.string(),
<http://Arb.int|Arb.int>(1..999)
) { randomItemId, randomQuantity ->
CartLineItemEntityBuilder()
.itemId(randomItemId)
.quantity(randomQuantity)
.build()
}
val cartEntityArb: Arb<CartEntity> = Arb.bind(
Arb.string(),
Arb.double(),
<http://Arb.int|Arb.int>()
) { randomId, randomAmount, randomItemCount ->
val amount = AmountBuilder().value(randomAmount).build()
CartEntityBuilder()
.cartId(randomId)
.grandTotal(amount)
.subtotal(amount)
.totalDiscount(amount)
.numberOfItems(randomItemCount)
//TODO how do i create a random list of CartLineItems?
.itemList(listOf(cartItemArb.single()))
.build()
}
checkAll(cartEntityArb) { cartEntity ->
val result = Cart.fromCartEntity(cartEntity)
result.workfile shouldBe cartEntity.cartId
}
}
})
How do I populate itemList in my cartEntityArb
with a list of cartItemArbs
?Jim
01/08/2021, 10:25 PM./gradlew test
?
test.doFirst {
System.setProperty("kotest.tags", "Unit")
}
Shalom Halbert
01/11/2021, 9:53 PMtaer
01/12/2021, 3:02 PMJoel Hess
01/13/2021, 9:37 PMfun <T> assertValidation(o: Any, validation: Class<T>, propertyName: String? = null) {
val violations = when (propertyName) {
null -> validator.validate(o)
else -> validator.validateProperty(o, propertyName)
}
assertAll(
Executable {
assertEquals(
1,
violations.count(),
"Expecting one violation, received ${violations.count()}"
)
},
Executable {
violations.forEach { violation ->
val annotation = violation.constraintDescriptor.annotation
assertThat(annotation, instanceOf(validation))
}
}
)
I’m trying to convert the type assertion to use ShouldBeInstanceOf<t> but the compiler doesn’t like it because its a generic type. I’m trying to change it to something along the lines of
inline fun <reified T> assertValidation(o: Any, validation: Class<T>, propertyName: String? = null) {
val violations = when (propertyName) {
null -> validator.validate(o)
else -> validator.validateProperty(o, propertyName)
}
assertSoftly {
withClue("Expecting one violation, received ${violations.count()}") {
violations.shouldHaveSize(1)
}
violations.forEach { violation ->
val annotation = violation.constraintDescriptor.annotation
annotation.shouldBeInstanceOf<validation>()
//assertThat(annotation, instanceOf(validation))
}
}
}
How can I use ShouldBeInstanceOf in this case?kopper
01/18/2021, 12:41 AMMikhail Galanin
01/19/2021, 10:40 AMStringSpecScope
doesn’t implement ContainerScope
? It appeared that I can’t use io.kotest.core.datatest.forAll
inside StringSpec
(or I haven’t found a way…)Hugo Martins
01/20/2021, 6:56 PMkotest
and thank you for all the work! I have a question, if anyone is available to answer it: I want to generate HTML reports from XML reports (built with Junit XML listener), with Gradle. I can’t seem to find a way to do it without any extra Gradle plugin. Is anyone aware of a listener (similar to what JUnit XML) that will allow me to run this after executing the entire kotest
test suite? Thank you!Animesh Sahu
01/21/2021, 5:18 AMLuis Daivid
01/21/2021, 5:37 AMLuis Daivid
01/24/2021, 11:01 AMjava.lang.IllegalArgumentException: failed to configure io.kotest.extensions.robolectric.ContainedRobolectricRunner$PlaceholderTest.testPlaceholder: Package targetSdkVersion=30 > maxSdkVersion=29
at org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:254)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner.access$getChildren(ContainedRobolectricRunner.kt:7)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner$placeHolderMethod$2.invoke(ContainedRobolectricRunner.kt:10)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner$placeHolderMethod$2.invoke(ContainedRobolectricRunner.kt:7)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner.getPlaceHolderMethod(ContainedRobolectricRunner.kt)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner.access$getPlaceHolderMethod$p(ContainedRobolectricRunner.kt:7)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner$sdkEnvironment$2.invoke(ContainedRobolectricRunner.kt:19)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner$sdkEnvironment$2.invoke(ContainedRobolectricRunner.kt:7)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at io.kotest.extensions.robolectric.ContainedRobolectricRunner.getSdkEnvironment(ContainedRobolectricRunner.kt)
at io.kotest.extensions.robolectric.RobolectricExtension.instantiate(RobolectricExtension.kt:16)
at io.kotest.engine.InstantiateSpecKt.createAndInitializeSpec(instantiateSpec.kt:21)
at io.kotest.engine.spec.SpecExecutor.createInstance(SpecExecutor.kt:103)
at io.kotest.engine.spec.SpecExecutor.execute(SpecExecutor.kt:43)
at io.kotest.engine.KotestEngine$submitBatch$$inlined$forEach$lambda$1$1.invokeSuspend(KotestEngine.kt:139)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:270)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at io.kotest.engine.KotestEngine$submitBatch$$inlined$forEach$lambda$1.run(KotestEngine.kt:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
test code is here:
@RobolectricTest
@Config(sdk = [Build.VERSION_CODES.P])
class ExampleUnitTest: FunSpec ({
test("test") {
"aa" shouldBe "aa"
}
})
How can i fix it?Steffen Haase
01/25/2021, 11:57 AMrelaxed=true
. my env is kotlin, mockk and kotest .
relaxed - allows creation with no specific behaviourin my case I expect an unspecified SimpleDataClass, something like
SimpleDataClass(a = null)
. In debug mode I can see that a = null
but if( a != null)
is true.
I created a litte playground https://github.com/cryptoki/kotest-mockk-relaxed
The picture shows the debugger output. Any ideas why the behaviour is like that? With relaxed=true
there is a big space for mistakes if I’m bit lazy with my test. thanks.mboudraa
01/28/2021, 4:25 PMpackage com.bethesomm.firebase.auth
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.ints.shouldBeExactly
class FirebaseUserTest : FunSpec({
test("should do whatever") {
"hello".length shouldBeExactly 5
}
})
I have the following error message [java.lang.ClassNotFoundException: com.bethesomm.firebase.auth.FirebaseUserTest]
Did I miss something?
FYI, I’m using the version 4.4.0.RC2mboudraa
01/28/2021, 4:33 PMmboudraa
01/28/2021, 4:59 PMImran/Malic
01/29/2021, 4:56 PMio.kotest:kotest-property
. I have some Tests that fail every now and then and I wanted to save those edgecases, to ensure that their fixedImran/Malic
01/29/2021, 4:56 PMio.kotest:kotest-property
. I have some Tests that fail every now and then and I wanted to save those edgecases, to ensure that their fixedsam
01/29/2021, 5:03 PMImran/Malic
01/29/2021, 7:33 PMjava.lang.AssertionError: Property failed after 1 attempts
Repeat this test by using seed 6157672104206447713
but in the application I am running the prop tests against I sometimes run into test error’s, where this is not suppliedsam
01/29/2021, 7:37 PMImran/Malic
01/29/2021, 7:57 PMsam
01/29/2021, 7:58 PMImran/Malic
01/29/2021, 7:58 PMsam
01/29/2021, 7:58 PMtest("foo") {
checkAll<String> { a -> error(boom") }
}
test("errored test should print seed") {
checkAll<Int, Int> { _, _ -> error("boom") }
}
Imran/Malic
01/29/2021, 8:03 PMtest("foo") {
forAll(Arb.list(Arb.domainType) { records ->
saveElementsToDB(records)
record == collectRecordsfromDB()
}
}
in some cases one or two elemts are missingsam
01/29/2021, 8:03 PMProperty failed after 1 attempts
java.lang.AssertionError: Property failed after 1 attempts
Repeat this test by using seed -3454921614817430845
Imran/Malic
01/29/2021, 8:04 PMsam
01/29/2021, 8:05 PMImran/Malic
01/29/2021, 8:05 PM