|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.qualitytest.blueprint.Blueprint
public final class Blueprint
Blueprinting is a technique that makes writing test easier. For unit-testing you often need data-objects, where the
actual content of the objects does not matter. Blueprint
creates data-objects filled with random or defined
data automatically based on the "Blue-Print" which is the Class itself.
Blueprinting makes tests more maintainable as they depend less on test-data. Imagine, you add a new required
attribute to a class. Usually, you have to add this to all tests using this class. With blueprinting you just have to
add it to certain tests where the contents of the logic does actually matter. Most of the time the randomly generated
value by Blueprint
is just fine.
Blueprint
is similar to C#'s AutoFixture (https://github.com/AutoFixture/AutoFixture#readme).
A simple example:
final BlueprintConfiguration config = new RandomBlueprintConfiguration().with("email", "mail@example.com"); final User user = Blueprint.construct(User.class, config);or simpler
final User user = Blueprint.random().with("email", "mail@example.com").construct(User.class);
Blueprint
offers two custom configurations. A DefaultBlueprintConfiguration
which fills any object
using default, empty or 0 values. The second configuration, RandomBlueprintConfiguration
will always generate
a random value. Both fill child objects using a deep-tree-search.
Utilities for collections can be found in CollectionBlueprint
.
DefaultBlueprintConfiguration
,
RandomBlueprintConfiguration
Method Summary | ||
---|---|---|
static
|
construct(Class<T> clazz)
Construct a Java-Object using a class as a blueprint. |
|
static
|
construct(Class<T> clazz,
BlueprintConfiguration config)
Construct a Java-Object using a class as a blueprint. |
|
static
|
construct(Class<T> clazz,
BlueprintConfiguration config,
BlueprintSession session)
Construct a Java-Object using a class as a blueprint. |
|
static BlueprintConfiguration |
def()
Return a new configuration for default blueprinting with zero or empty default values. |
|
protected static boolean |
isRelevant(Method m)
Check if a method is setter according to the java |
|
static BlueprintConfiguration |
random()
Return a new configuration for random blueprinting. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
@Nullable public static <T> T construct(@Nonnull Class<T> clazz)
T
- clazz
- a class
T
@Nullable public static <T> T construct(@Nonnull Class<T> clazz, @Nonnull BlueprintConfiguration config)
T
- clazz
- a classconfig
- a BlueprintConfiguration
T
@Nullable public static <T> T construct(@Nonnull Class<T> clazz, @Nonnull BlueprintConfiguration config, @Nonnull BlueprintSession session)
T
- clazz
- a classconfig
- a BlueprintConfiguration
session
- a BlueprintSession
T
public static BlueprintConfiguration def()
DefaultBlueprintConfiguration
protected static boolean isRelevant(Method m)
m
- a method
public static BlueprintConfiguration random()
RandomBlueprintConfiguration
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |