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

Test utility to minimise code duplication for repetitive test cases.

test_in_case #

A dart test utility for creating variations of the same test using multiple cases. Write the testing logic once and provide a list of cases to test. Inspired by jest-in-case.

Installation #

  dart pub add test_in_case --dev
  
  OR
  
  flutter pub add test_in_case --dev

Usage #

Import the test_in_case package. Use the cases function to define the tests. It takes in three parameters:

  • title: The title of the group of tests.
  • cases: A list of TestCase objects.
  • tester: Pass a the testing logic as a callback which will be called for each test case. The test case object is passed to the callback as an argument.

Call the cases function with a type parameter(cases<T>), which will be used as the type of the test case in the TestCase object.

  import 'package:test_in_case/test_in_case.dart';
  
  cases<int>(
    title: 'Even Numbers'
    cases: [1, 2, 3]
        .map(
          (number) => TestCase(
            name: '$number is even',
            testCase: number,
          ),
        )
        .toList(),
    tester: (testCase) => expect(testCase % 2 ==0, true);
  );
3
likes
160
pub points
0%
popularity

Publisher

verified publishersmarak.dev

Test utility to minimise code duplication for repetitive test cases.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

meta, test

More

Packages that depend on test_in_case