zam_test 0.0.1 copy "zam_test: ^0.0.1" to clipboard
zam_test: ^0.0.1 copied to clipboard

outdated

A typed wrapper around the test package with several utilities for testing.

Zam Test Library #

zam_test is a typed version of the test package.

Version Build Style Stars CodeFactor License

What's inside the package #

Includes the following core components.

Check out all the components in detail here

How to use #

TestCase #

TestCase can be seen as the typed version of test() function in the original test package. It accepts two descriptive texts when and then, an input, a matcher and an optional callback called the action.

Simple way to execute a TestCase is as follows.

void main() {
  ValueTestCase(
    when: 'Positive Border height value',
    then: 'outputs value in m',
    input: 1.0,
    output: '0.01 m',
    action: (double input) => Height(input).toStringInMetre(),
  ).execute();
}

Currently we have provided two basic test case types which derive from TestCase. We expect this list to grow in the future to handle various scenarios. Until then you can use TestCase since it accepts a custom matcher.

TestGroup #

TestGroup is synonymous to group() function. You can wrap multiple test cases in a TestGroup. You can create a new test group class by extending TestGroup by following the steps given below.

  • Create a class extending TestGroup.
  • Provide a name.
  • Override run which is a function called for every TestCase.
  • Provide a list of testCases.
  • Override setUp and tearDown when required.
  • You can optionally override the nameSuffix and the description.
void main() {
  HeightTest().execute();
}

class HeightTest extends TestGroup<double, String> {
  @override
  final name = 'Height';

  @override
  run(input) {
    return Height(input).toStringInMetre();
  }

  @override
  final testCases = [
    NegativeTestCase(
      when: 'Negative Border height value',
      input: -1,
      exception: HeightNotValidException,
    ),
    NegativeTestCase(
      when: 'Zero height value',
      input: 0,
      exception: HeightNotValidException,
    ),
    ValueTestCase(
      when: 'Positive Border height value',
      then: 'outputs value in m',
      input: 1,
      output: '0.01 m',
    ),
  ];
}

TestRun #

TestRun is used to run multiple TestGroup together. It is more of a utility class. You can run test groups without this.

void main() {
  TestRun('All Tests', [
    HeightTest(),
    // WeightTest(),
    // BmiTest(),
    // ...
    // ...
    // ... (you can add more test groups here)
  ]).execute();
}

To learn more, check out this dedicated example in github.

Customization #

You can override the following at the moment.

  • TestCase -> descriptionDelimiter - Defaults to ' -> '.
  • TestCase -> description - It is generated by combining the when and then texts with a descriptionDelimiter in between.
  • TestGroup -> nameSuffix - Defaults to ':'.
  • TestGroup -> description - It is generated by combining name and nameSuffix.

Contributors #

  • Amsakanna
0
likes
0
pub points
0%
popularity

Publisher

verified publisherzamstation.com

A typed wrapper around the test package with several utilities for testing.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

test, zam_core

More

Packages that depend on zam_test