-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 (#47): Ensure tests are reproducible in JUnit5
- Loading branch information
Showing
4 changed files
with
160 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
junit5/src/test/java/fr/xgouchet/elmyr/junit5/JavaReproducibilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package fr.xgouchet.elmyr.junit5; | ||
|
||
import fr.xgouchet.elmyr.Forge; | ||
import fr.xgouchet.elmyr.annotation.FloatForgery; | ||
import fr.xgouchet.elmyr.annotation.Forgery; | ||
import fr.xgouchet.elmyr.annotation.IntForgery; | ||
import fr.xgouchet.elmyr.junit5.dummy.Bar; | ||
import fr.xgouchet.elmyr.junit5.dummy.Foo; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
@ExtendWith(ForgeExtension.class) | ||
@ForgeConfiguration(value = JavaAnnotationTest.Configurator.class, seed = JavaReproducibilityTest.SEED) | ||
public class JavaReproducibilityTest { | ||
|
||
public static final long SEED = 0x85F04771A07L; | ||
|
||
@Forgery | ||
private Foo fakeFoo = null; | ||
|
||
@Forgery | ||
public Bar fakeBar = null; | ||
|
||
@BeforeEach | ||
public void setUp(Forge forge) { | ||
checkSeedNotChanged(forge); | ||
checkForgeryInjected(); | ||
} | ||
|
||
@Test | ||
public void testRun1() { | ||
} | ||
|
||
@Test | ||
public void testRun2() { | ||
} | ||
|
||
@Test | ||
public void testRun3(@Forgery Foo foo, @Forgery Bar bar) { | ||
assertThat(foo.getI()).isEqualTo(-1314996441); | ||
assertThat(bar.getS()).isEqualTo("xiqcgqfmbjoaevbo"); | ||
} | ||
|
||
@Test | ||
public void testRun4(@FloatForgery float f, @IntForgery int i) { | ||
assertThat(f).isEqualTo(3.1084288E38f); | ||
assertThat(i).isEqualTo(177874237); | ||
} | ||
|
||
private void checkSeedNotChanged(Forge forge) { | ||
assertThat(forge.getSeed()).isEqualTo(SEED); | ||
} | ||
|
||
private void checkForgeryInjected() { | ||
assertThat(fakeFoo.getI()).isEqualTo(-119626925); | ||
assertThat(fakeBar.getS()).isEqualTo("ttcji"); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
junit5/src/test/kotlin/fr/xgouchet/elmyr/junit5/KotlinReproducibilityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package fr.xgouchet.elmyr.junit5 | ||
|
||
import fr.xgouchet.elmyr.Forge | ||
import fr.xgouchet.elmyr.ForgeConfigurator | ||
import fr.xgouchet.elmyr.annotation.FloatForgery | ||
import fr.xgouchet.elmyr.annotation.Forgery | ||
import fr.xgouchet.elmyr.annotation.IntForgery | ||
import fr.xgouchet.elmyr.junit5.dummy.Bar | ||
import fr.xgouchet.elmyr.junit5.dummy.BarFactory | ||
import fr.xgouchet.elmyr.junit5.dummy.Foo | ||
import fr.xgouchet.elmyr.junit5.dummy.FooFactory | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(ForgeExtension::class) | ||
@ForgeConfiguration(value = KotlinReproducibilityTest.Configurator::class, seed = KotlinReproducibilityTest.SEED) | ||
class KotlinReproducibilityTest { | ||
|
||
@Forgery | ||
private lateinit var fakeFoo: Foo | ||
@Forgery | ||
private lateinit var fakeBar: Bar | ||
|
||
@BeforeEach | ||
fun setUp(forge: Forge) { | ||
checkSeedNotChanged(forge) | ||
checkForgeryInjected() | ||
} | ||
|
||
@Test | ||
fun testRun1() { | ||
} | ||
|
||
@Test | ||
fun testRun2() { | ||
} | ||
|
||
@Test | ||
fun testRun3(@Forgery foo: Foo, @Forgery bar: Bar) { | ||
assertThat(foo.i).isEqualTo(1834174735) | ||
assertThat(bar.s).isEqualTo("wfpwhlvm") | ||
} | ||
|
||
@Test | ||
fun testRun4(@FloatForgery f: Float, @IntForgery i: Int) { | ||
assertThat(f).isEqualTo(2.5332062E38f) | ||
assertThat(i).isEqualTo(-1217237951) | ||
} | ||
|
||
private fun checkSeedNotChanged(forge: Forge) { | ||
assertThat(forge.seed).isEqualTo(SEED) | ||
} | ||
|
||
private fun checkForgeryInjected() { | ||
assertThat(fakeFoo.i).isEqualTo(1596512190) | ||
assertThat(fakeBar.s).isEqualTo("grquxsqwqccdwk") | ||
} | ||
|
||
class Configurator : ForgeConfigurator { | ||
override fun configure(forge: Forge) { | ||
forge.addFactory(Foo::class.java, FooFactory()) | ||
forge.addFactory(Bar::class.java, BarFactory()) | ||
} | ||
} | ||
companion object { | ||
const val SEED = 0xD774670189EL | ||
} | ||
} |