-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for deterministic testing with JUnit
- Loading branch information
Showing
7 changed files
with
204 additions
and
44 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/engine/EngineUtils.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,42 @@ | ||
package com.navercorp.fixturemonkey.api.engine; | ||
|
||
import org.apiguardian.api.API; | ||
import org.apiguardian.api.API.Status; | ||
|
||
/** | ||
* The {@link EngineUtils} class provides utility methods for engine. | ||
* Engine is a library that provides a way to generate random values. | ||
*/ | ||
@API(since = "1.1.9", status = Status.EXPERIMENTAL) | ||
public abstract class EngineUtils { | ||
private static final boolean USE_JQWIK_ENGINE; | ||
private static final boolean USE_KOTEST_ENGINE; | ||
|
||
static { | ||
boolean useJqwikEngine; | ||
boolean useKotestEngine; | ||
try { | ||
Class.forName("net.jqwik.engine.SourceOfRandomness"); | ||
useJqwikEngine = true; | ||
} catch (ClassNotFoundException e) { | ||
useJqwikEngine = false; | ||
} | ||
USE_JQWIK_ENGINE = useJqwikEngine; | ||
|
||
try { | ||
Class.forName("io.kotest.property.Arb"); | ||
useKotestEngine = true; | ||
} catch (ClassNotFoundException e) { | ||
useKotestEngine = false; | ||
} | ||
USE_KOTEST_ENGINE = useKotestEngine; | ||
} | ||
|
||
public static boolean useJqwikEngine() { | ||
return USE_JQWIK_ENGINE; | ||
} | ||
|
||
public static boolean useKotestEngine() { | ||
return USE_KOTEST_ENGINE; | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
...arks/fixture-monkey-benchmark/src/jmh/java/com/navercorp/fixturemonkey/SeedBenchmark.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,73 @@ | ||
/* | ||
* Fixture Monkey | ||
* | ||
* Copyright (c) 2021-present NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.fixturemonkey; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import com.navercorp.fixturemonkey.api.random.Randoms; | ||
import com.navercorp.fixturemonkey.api.type.TypeCache; | ||
import com.navercorp.fixturemonkey.javax.validation.plugin.JavaxValidationPlugin; | ||
|
||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
public class SeedBenchmark { | ||
private static final int SEED = 1234; | ||
private static final int COUNT = 500; | ||
private static final FixtureMonkey SUT = FixtureMonkey.builder() | ||
.plugin(new JavaxValidationPlugin()) | ||
.seed(SEED) | ||
.build(); | ||
|
||
@Setup(value = Level.Iteration) | ||
public void setUp() { | ||
TypeCache.clearCache(); | ||
} | ||
|
||
@Benchmark | ||
public void eachIterationCreatesNewJqwikSeed(Blackhole blackhole) throws Exception { | ||
Randoms.newGlobalSeed(SEED); | ||
blackhole.consume(generateOrderSheet()); | ||
} | ||
|
||
@Benchmark | ||
public void eachIterationNotCreatesNewJqwikSeed(Blackhole blackhole) throws Exception { | ||
blackhole.consume(generateOrderSheet()); | ||
} | ||
|
||
private List<OrderSheet> generateOrderSheet() { | ||
List<OrderSheet> result = new ArrayList<>(); | ||
for (int i = 0; i < COUNT; i++) { | ||
result.add(SeedBenchmark.SUT.giveMeOne(OrderSheet.class)); | ||
} | ||
return result; | ||
} | ||
} |
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
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