Class FieldTests
For each field bar of model element Foo a test method
test_Foo_bar is generated. The test creates an instance of
Foo, sets bar to a randomly chosen value (via the
setter for mutable classes, or via with_bar for algebraic
classes), reads it back through the getter, and asserts equality.
For each model element Foo an aggregating method
test_Foo__fields is generated that calls every per-field test.
OPT fields are tested with a null round-trip. Fields whose
types have no straightforward random generator (collections, non-OPT
internal references, external types, etc.) are omitted.
When a class has required constructor parameters (i.e.
UMod.ClassDef.obligateConstructorFields is non-empty), an abstract
factory method createInstance_ClassName() is generated instead of
an inline new ClassName(). In that case the generated test class
is made abstract and must be subclassed by the user.
This class must be called after the field-definition
compilation phase of UMod2java so that
ClassDef.obligateConstructorFields and the Java type mappings of
all fields are already populated.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFieldTests(UMod.Forest model, GeneratedPackage pkg) Store the arguments; callprocess()to run the generation. -
Method Summary
Modifier and TypeMethodDescriptionvoidprocess()Create and populate the test class for all class definitions in the model passed to the constructor.
-
Field Details
-
TESTCLASS_NAME_PREFIX
Prefix prepended to the model name to form the test-class name.- See Also:
-
testClass
The generated JUnit test class; set byprocess().
-
-
Constructor Details
-
FieldTests
Store the arguments; callprocess()to run the generation.- Parameters:
model- the compiled umod meta-model (field phases must be done)pkg- the target package for the generated test class
-
-
Method Details
-
process
public void process()Create and populate the test class for all class definitions in the model passed to the constructor.
-