Is there is any way to capture print() statement during integration test

406

Maybe this will help you?

import 'dart:async';
import 'dart:developer';

void main(List<String> args) async {
  final printed = <String>[];
  final result = runZoned(() => foo(), zoneSpecification: ZoneSpecification(
    print: (self, parent, zone, line) {
      printed.add(line);
    },
  ));

  print('Result: $result');
  print('Printed:\n${printed.join('\n')}');
  debugger();
}

int foo() {
  print('Hello');
  print('Goodbye');
  return 41;
}

P.S.
I added a debugger call so that the result of the work was visible. This statement can (and should) be removed.

Share:
406
Nikhil Soni
Author by

Nikhil Soni

Updated on January 04, 2023

Comments

  • Nikhil Soni
    Nikhil Soni over 1 year

    Is there is any way during the integration testing to monitor or save or read whatever the print() statement is printing to the console. I m using integration_test for testing.