Skip to content

Commit

Permalink
preparing for 0.1 beta release.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjstehno committed Nov 21, 2022
1 parent afd1810 commit e68bba1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Project artifacts are available via the Maven Central repository. Below are the
Gradle

```groovy
testImplementation 'io.github.cjstehno:test-things:0.0.1'
testImplementation 'io.github.cjstehno:test-things:0.1.0'
```

Maven
Expand All @@ -31,7 +31,7 @@ Maven
<dependency>
<groupId>io.github.cjstehno</groupId>
<artifactId>test-things</artifactId>
<version>0.0.1</version>
<version>0.1.0</version>
<scope>test</scope>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = 'io.github.cjstehno'
version = '0.0.2'
version = '0.1.0'

sourceCompatibility = 17
targetCompatibility = 17
Expand Down
44 changes: 27 additions & 17 deletions src/docs/asciidoc/randomizers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@

Testing with randomized values may sound like an odd concept, but it does have its uses. Consider a case where there are too many permutations of a scenario to adequately test all of them. You could create a randomized set of test values to run against and run your test multiple times - sure, you still don't hit them all, but you may stumble on a set that does fall into some hidden bug that your static tests would not have found.

The test-things library provides a `Randomizer<T>` interface to define a means of randomly generating objects or values. It's primary method of interest is the `T one()` method, which generates one randomized object of the specific type.
The Test-Things library provides a `Randomizer<T>` interface to define a means of randomly generating objects or values. It's primary method of interest is the `T one()` method, which generates one randomized object of the specific type, though you can generate multiple random instances using the `List<T> many(int)` method as well.

The library provides a handful of `Randomizer<T>` implementations, including the most useful one, the `ObjectRandomizer` which allows you to build more complex randomized objects using randomized values for the fields and properties.
The library provides a handful of `Randomizer<T>` implementations, including the `ObjectRandomizers` which allow you to build more complex randomized objects using randomized values for the fields and properties of a given object - combining injectors with randomizers.

The `ObjectRandomizer` is configured with an `ObjectRandomizerConfig` object directly or via a `Consumer`:

>> this is obsolete just use injector - document
Given some class for which to generate random instances, such as:

[source,java]
----
var rando = ObjectRandomizer.randomize(ComplexObject.class, cfg -> {
cfg.property("id", randomString(10));
cfg.property("shipmentSize", randomInt(0, 155));
});
public class Thing {
ThingType type;
int count;
private String name;
public void setName(final String name){
this.name = name;
}
public String getName(){
return name;
}
}
----

The above code would configure a randomizer (generally called a "rando") for `ComplexObject` instances with a random string "id" and random int "shipmentSize" value when generated. You can then generate one or more random instances as:
You can generate random instances of `Thing` using:

[source,java]
----
var single = rando.one();
val list = rando.many(7);
val rando = ObjectRandomizers.randomized(new Thing(), inj -> {
inj.setField("type", CoreRandomizers.oneOf(ThingType.class));
inj.setField("count", NumberRandomizers.anIntBetween(0,1000));
inj.setProperty("name", StringRandomizers.alphabetic(CoreRandomizers.constant(6)));
});
----

more details about the configuration of the object randomizer

#person randomizer#

Which would generate a random `Thing` by directly injecting the `type` and `count` fields using values from the provided randomizers, while also injecting the random value for the `name` field by first trying to use the "setter" for the property.

With this framework, you can generate complex random instances as simply as you can generate random primitive values.

TIP: You can "pin" the randomizers so that they will produce the same values - see the `SharedRandom` class for details. This allows you to reproduce failing test values.

=== SharedRandom

#talk about the shared random class#
All of the `Randomizer<T>` implementations provided in this toolkit use the `SharedRandom` class to provide the random values. This class is based on the standard `ThreadLocalRandom` class, but it provides a means of easily overriding the seed value, which is useful for "pinning" the random values for testing.

The seed value may be overridden directly in the instance, or a system property `test-things.rando.seed` may be set to configure the JVM-wide seed value to be used.
11 changes: 10 additions & 1 deletion src/docs/asciidoc/serdes.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
== Serdes Providers

what it says on the box...
Some of the resource and verification method require serialization operations to load or verify content based on serialized or deserialized values. In order to keep things as generic as possible, Test-Things provides a `SerdesProvider` interface to abstract the actual "Ser"ialization and "Des"erialization operations (SerDes).

Currently, there are three provided implementations:

* `JacksonJsonSerdes` - JSON-based serdes using the Jackson JSON `ObjectMapper`
* `JacksonXmlSerdes` - XML-based serdes using the Jackson XML `XmlMapper`
* `JavaObjectSerdes` - standard Java object binary serdes using the `ObjectInputStream` and `ObjectOutputStream`
NOTE: Some of the serdes-based resource and verification methods are provided without a `SerdesProvider` parameter, which generally means they are using the `JacksonJsonSerdes` provider - a sensible default.
23 changes: 23 additions & 0 deletions src/docs/asciidoc/user_guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ attempt to formalize these tools into a cohesive codebase and provide them for o
*Test Things?* Is it a statement, as in "things for testing", or is it a command, telling you to "go forth and test"? It's
up to you.

WARNING: This is project is considered a BETA release at this point. I don't foresee any breaking changes at this point, but keep in mind that until a 1.0.0 release things are subject to change.

== Getting Started

The Test-Things artifacts are available via the Maven Central repository. Below are the dependency coordinates for Gradle and Maven.

For Gradle:

----
testImplementation 'io.github.cjstehno:test-things:0.1.0'
----

For Maven:

----
<dependency>
<groupId>io.github.cjstehno</groupId>
<artifactId>test-things</artifactId>
<version>0.1.0</version>
<scope>test</scope>
</dependency>
----

include::fixtures.adoc[]

include::junit_extensions.adoc[]
Expand Down

0 comments on commit e68bba1

Please sign in to comment.