Customizing Tests

Standard test parameters

The modddels test methods (isValid, isSanitized ...) can receive the same parameters as the test function (Except description and body).

These parameters are : testOn - timeout - skip - tags - onPlatform - retry

For example :

testAge.isValid(
  const AgeParams(19),
  skip: true,
  retry: 3,
);

For more information, check out the documentation of the test function.

Test Description

Each test's description is automatically generated. It uses the Gherkin syntax (given-when-then).

For isValid tests :

Given a {modddelName} {modddelKind}
When instantiated with {params}
Then the {modddelName} is a {validName}

For isSanitized tests :

Given a {modddelName} {modddelKind}
When instantiated with {params}
Then the {modddelName} holds {sanitizedParams}

For isInvalid tests :

Given a {modddelName} {modddelKind}
When instantiated with {params}
Then the {modddelName} is an {invalidStepName}
# If the failure argument of `isInvalid` is null :
And has no {failure1Name}
# If the failure argument of `isInvalid` is not null :
And has a {failure1Name} that equals {failure1}
# ... (one line for each failure argument)

Example : For this test :

testAge.isInvalidValue(
  const AgeParams(12),
  legalFailure: const AgeLegalFailure.minor(),
);

The generated description is :

Given a Age SingleValueObject
When instantiated with (value: 12)
Then the Age is an InvalidAgeValue
And has a AgeLegalFailure that equals AgeLegalFailure.minor()

The maxTestInfoLength

As you can see, the description can contain {params}, {sanitizedParams} and {failure}. These can be quite long strings, which would cause the description to become too long and unreadable.

To keep the description short enough, each one of those strings' length is limited to maxTestInfoLength, beyond which they are ellipsized. This maxTestInfoLength defaults to 200 characters, but it can be modified by :

  1. Providing it in the modddel annotation :

    @Modddel(
      // validationSteps: [...],
      maxTestInfoLength: 50,
    )
    // class Name extends SingleValueObject ...
  2. Providing it in the Tester's constructor. This takes priority over maxTestInfoLength set in @Modddel.

    const testName = TestName(maxTestInfoLength: 20);
  3. Providing it in the test method itself. This takes priority over maxTestInfoLength set in the Tester's constructor.

    testName.isValid(
      const NameParams('This is a very long name'),
      maxTestInfoLength: 10,
    );

This "ellipsisation" can be disabled by setting maxTestInfoLength to Modddel.noMaxLength (which equals -1).