xgouchet / Elmyr

A utility to make Kotlin/Java tests random yet reproducible
Other
82 stars 2 forks source link

Can not set a seed with the default ForgeConfigurator #54

Closed vincent314 closed 3 years ago

vincent314 commented 3 years ago

Hi,

I was just testing your lovely library after watching this video on youtube, and just got an error : I can not replay a test with a seed and the default ForgeConfigurator. It also happen with just @ForgeConfiguration (no seed and no Configurator provided)

class fr.xgouchet.elmyr.junit5.ForgeExtension cannot access a member of class fr.xgouchet.elmyr.ForgeConfigurator$NoOp with modifiers "private"
java.lang.IllegalAccessException: class fr.xgouchet.elmyr.junit5.ForgeExtension cannot access a member of class fr.xgouchet.elmyr.ForgeConfigurator$NoOp with modifiers "private"
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
    at java.base/jdk.internal.reflect.Reflection.ensureMemberAccess(Reflection.java:99)
    at java.base/java.lang.Class.newInstance(Class.java:579)
    at fr.xgouchet.elmyr.junit5.ForgeExtension.getConfigurators(ForgeExtension.kt:193)
    at fr.xgouchet.elmyr.junit5.ForgeExtension.beforeAll(ForgeExtension.kt:66)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$7(ClassBasedTestDescriptor.java:359)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at 
[...]

Here is my very basic test class:

import fr.xgouchet.elmyr.annotation.IntForgery
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
import fr.xgouchet.elmyr.junit5.ForgeExtension
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(ForgeExtension::class)
@ForgeConfiguration(seed = 0x2af7b7def4L)
class FooTest {
    @Test
    fun testSomething(@IntForgery i: Int) {
        i % 2 shouldBe 0
    }
}

version: 1.2.0 kotlin: 1.4.20 junit: 5.6.0

xgouchet commented 3 years ago

Hi @vincent314, this seems like a weird issue, let me jump on it I'll try and fix it quickly.

xgouchet commented 3 years ago

After some investigation, this seem to only happen when kotest is used. I've not tested Elmyr with Kotest since it already has a property based testing support.

xgouchet commented 3 years ago

This was just fixed in version 1.3.1