dart-test
dart pub add dev:tracera_test
Requires Dart ≥ 3.8 and package:test ≥ 1.25 (see Autotest adapters). tracera_test on pub.dev.
Environment variables and run mode: Autotest adapters.
Call installTracera() once at the top of the main function. Keep the stock package:test imports; add only installTracera and the tracera calls:
import 'package:test/test.dart';
import 'package:tracera/tracera.dart' as tracera;
import 'package:tracera_test/tracera_test.dart';
void main() {
installTracera();
test('user can sign in', () {
tracera.step('open login', () {
// ...
});
}, tags: ['tracera-id-42']);
}
Bind testCaseId and autotestName
Add the tag tracera-id-‹id› to a test or group. Add tracera-name-‹name› to set autotestName. A name tag cannot contain spaces; to use spaces, bind inside the test with tracera.testCase. If the name tag is omitted, autotestName takes the value of the package:test test name.
test('user can sign in', () {
// ...
}, tags: ['tracera-id-42', 'tracera-name-e2e_sign_in']);
test('user can sign out', () {
tracera.testCase(43, 'e2e/sign out');
});
To silence package:test warnings about undefined tags, list the Tracera tags under tags: in dart_test.yaml.
Skip
Call markTestSkipped('reason') inside the test. The result is reported as Skipped, and the reason is added to the result as comment.
test('checkout', () {
markTestSkipped('needs a seeded account');
}, tags: ['tracera-id-42']);
The skip: argument on test or group is not reported.
Steps
Use tracera.step('…', () { … }). A setUp callback maps to Setup, the test body to Test, and a tearDown callback to Teardown. Steps inside setUpAll / tearDownAll are not reported.
setUp(() {
tracera.step('open shop', () {});
});
test('checkout', () async {
tracera.testCase(10);
await tracera.step('add item', () async {
tracera.step('nested leaf', () {});
});
});
tearDown(() {
tracera.step('close shop', () {});
});
Comments, errors, and attachments
Limits and allowed MIME types: Autotest adapters.
tracera.comment, tracera.error, and attachments are added to the open step, or to the result when no step is open. tracera.attachmentFile takes a file path; tracera.attachmentBytes takes a name and bytes, with an optional mimeType. Attachments upload when the result is reported.
tracera.comment('result-level note');
tracera.error('result-level error');
tracera.attachmentFile('test/fixtures/screenshot.png');
tracera.step('open login', () {
tracera.comment('step note');
tracera.attachmentBytes(
'body.json',
utf8.encode('{"ok":true}'),
mimeType: 'application/json',
);
});
Parameterized
Create one test in a loop for each row. If the name is omitted, autotestName takes the value of the test name, so give each row a distinct title. To set a name per row, pass it to tracera.testCase:
for (final login in ['alice', 'bob']) {
test('sign in as $login', () {
tracera.testCase(7, 'login as $login');
});
}
When a test is retried with retry:, only the final attempt is reported. The result Env tab then includes DART_TEST_RETRY (see Autotest adapters).