Modddels
HomeGithubPub.dev
v0.1
v0.1
  • Motivation
  • Setup
  • Generalities
    • Modddels Overview
    • Validations & Validation steps
    • Structure of a Modddel
    • Member parameters & Dependency parameters
    • Usage
      • Data equality & toString
      • Pattern matching
      • Reading the fields
      • Reading the failures
      • CopyWith
  • ValueObjects
    • ValueObjects Overview
    • Creating a ValueObject
  • Entities
    • Entities Overview
    • ContentValidation & ContentFailure
    • ValidationSteps in Entities
    • SimpleEntity
      • Creating a SimpleEntity
      • Special Cases
    • IterableEntity & Iterable2Entity
      • IterableEntity / Iterable2Entity kinds
      • The Type Template
      • Creating an IterableEntity / Iterable2Entity
      • InvalidMembers Description
      • Special Cases
      • Creating your own IterableEntity / Iterable2Entity kind
  • Advanced Notions
    • The NullFailure Annotation
    • Using multiple parameters annotations
    • Class Hierarchy of ValueObjects
    • Class Hierarchy of Entities
    • Models that are always valid / invalid
  • Union of Modddels
    • Union of Modddels Overview
    • Basic Usage
    • Case-modddels pattern matching
    • Default Factory Constructor
    • Shared Properties
    • The Validate Methods
    • CopyWith
  • Unit-Testing Of Modddels
    • Unit-Testing Overview
    • Available Tests
    • Customizing Tests
  • Additional Information
    • Using type aliases
    • Re-running the generator
    • All Available Modddels
    • VsCode Snippets
Powered by GitBook
On this page
  • Standard test parameters
  • Test Description
  • The maxTestInfoLength
  1. Unit-Testing Of Modddels

Customizing Tests

PreviousAvailable TestsNextUsing type aliases

Last updated 2 years ago

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 of the test function.

Test Description

Each test's description is automatically generated. It uses the (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).

the documentation
Gherkin syntax