zam_test 0.3.0 copy "zam_test: ^0.3.0" to clipboard
zam_test: ^0.3.0 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 Stars License

What's inside the package #

Includes the following core components.

Check out all the components in detail here

How to use #

Summary #

  • Test is the main class. It has two constructor methods, the Test.single and the Test.multi. If your test is simple and has only one case, then use Test.single.
  • TestCase is something that is wrapped inside a Test.multiple. Avoid using a TestCase directly.
  • TestGroup is used to run multiple Test together.

Test #

Test can be seen as the typed version of test() function in the original test package. Mostly a Test will have multiple cases based on different inputs. For example, a login test has multiple test cases based on different inputs like wrong username, wrong password, correct username and password, etc. A Test can also have a single test case. Therefore, we have MultiCasedTest and SingleCasedTest respectively to address these.

You can also create a new test by extending Test by following the steps given below.

  • Create a class extending Test.
  • Provide a name.
  • Override run function which is called for every TestCase.
  • Provide a list of cases.
  • Override intialize and dispose when required.
  • You can customize the nameSuffix and the description too.
class HeightTest extends Test<double, String> {
  @override
  final name = 'Height';

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

  @override
  final cases = [
    NegativeTestCase(
      when: 'Negative height value',
      input: -23,
      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',
    ),
  ];
}

void main() {
  HeightTest().execute();
}

TestGroup #

TestGroup is used to run multiple Test together. It is more of a utility class. You can run tests without this.

void main() {
  TestGroup('BMI', [
    HeightTest(),
    // WeightTest(),
    // HeightTest(),
    // BmiCategoryTest(),
    // ...
    // ...
    // ... (you can add more test groups here)
  ]).execute();
}

TestCase #

It accepts two descriptive texts when and then, an input, a matcher and an optional callback called the action.

CONSIDER: Always consider executing it inside a Test class even when you want to run a single test case which is accomplished using Test.single constructor.

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.

Read More #

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.
  • Test -> nameSuffix - Defaults to ':'.
  • Test -> description - It is generated by combining name and nameSuffix.
  • TestGroup -> nameSuffix - Defaults to ' -'.
  • TestGroup -> description - It is generated by combining name and nameSuffix.

Contributors #

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