0

I am trying to understand and do research in order to find if it is possible to print the results of Flutter tests (integration/widget/unit) in a .md file.

Until now my research has not yielded many results. Does anyone have any more information or knowledge that can help me achieve this goal?

This is the closest result I reach:

  Future<void> main() async {
    
  testWidgets('Test App', (WidgetTester tester) async {
          ...
  });
    
  final String dirPath = "myPath/automatic";
  bool directoryExists = await Directory(dirPath).exists();
  if (!directoryExists) {
    await Directory(dirPath).create(recursive: true);
  }

  final _myFile = File('$dirPath/test-result.md');

  String result = "## Test";

  print(result);

  _myFile.writeAsString("\n\n"+result, mode: FileMode.append);

  tearDown(() {
    String testName = Invoker.current!.liveTest.test.name;
    String testGroupName = Invoker.current!.liveTest.groups[1].name;

    testName = testName.replaceFirst(testGroupName+" ","");

    if (Invoker.current!.liveTest.state.result == test_api.Result.error) {
      result = "- :no_entry_sign: " + testName;
    } else {
      result = "- [x] " + testName;
    }
    print(result);
    _myFile.writeAsString("\n" + result, mode: FileMode.append);
  });

It prints in the console the result of the test, it creates the .md file, but somehow the result is not printed on the file.

TheOldBlackbeard
  • 395
  • 4
  • 22

1 Answers1

0

Check this post. I think it contains what you want. All you need to do is running this command

flutter test --machine integration_test > reports/report.md

OmarYehiaDev
  • 153
  • 1
  • 8