zam_test 0.0.1 zam_test: ^0.0.1 copied to clipboard
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.
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.
- ValueTestCase - To match direct values.
- NegativeTestCase - To match exceptions.
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 everyTestCase
. - Provide a list of
testCases
. - Override
setUp
andtearDown
when required. - You can optionally override the
nameSuffix
and thedescription
.
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
andthen
texts with adescriptionDelimiter
in between. - TestGroup -> nameSuffix - Defaults to
':'
. - TestGroup -> description - It is generated by combining
name
andnameSuffix
.
Contributors #
- Amsakanna