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

Helper for getting the `print` output in tests.

run_with_print #

A helper for getting the print output in tests.

Introduction #

Sometimes, you want to check the print output when you test the app or test Command Line Interface.

This package returns the print output to help you to check it in the test code.

Installing #

You can install this package by executing the following command.

dart pub add --dev run_with_print

Or, open the pubspec.yaml file and add the run_with_print package to dev_dependencies as follows.

...
dev_dependencies:
  run_with_print: [version]
...

Example #

You can use the runWithPrint function to get the print output. A full test example could look like the following.

import 'package:run_with_print/run_with_print.dart';
import 'package:test/test.dart';

void main() {
  test('Check print contents', () {
    runWithPrint((logs) {
      print('test log');
      expect(logs[0], 'test log');

      print('test message');
      expect(logs[1], 'test message');
    });
  });
}

You can just wrap the test code with runWithPrint(() {}); to get the print output.

Contributing #

If you want to contribute to this package, please see CONTRIBUTING.

0
likes
140
points
183
downloads

Publisher

unverified uploader

Weekly Downloads

Helper for getting the `print` output in tests.

Documentation

API reference

License

MIT (license)

More

Packages that depend on run_with_print