Unit-Testing Overview
Modddels come with a simplified way to unit-test them.
Let's say you have an Age ValueObject you want to unit-test. First, in the @Modddel annotation, set generateTestClasses to true :
@Modddel(
validationSteps: [
ValidationStep(
[Validation('legal', FailureType<AgeLegalFailure>()),],
),
],
generateTestClasses: true,
)This will generate two classes :
TestAge: This is what we call the "Tester". It allows you to create tests.AgeParams: This is what we call the "ModddelParams". It represents the parameters of the modddel.
Now, in your unit-test file, you can start adding some tests this way :
void main() {
// 1.
const testAge = TestAge();
// 2.
group('Scenario : Age is valid', () {
//3.
testAge.isValid(const AgeParams(19));
testAge.isValid(const AgeParams(20));
});
}As you can see :
You create an instance of the Tester
Optionally, you can group your tests in
groupmethodsYou add your tests. In this example, we created two tests : the first one verifies that the
Ageis valid when given19as an argument, and the second20.
Last updated