flutter integration test multiple files and tests

578 views Asked by At

Im using the integration_test package.

Based on this thread I've tried to run multiple tests on different files.

Test two depends on Test one!! but can also run independently.

Since "group" is not allowed to have "await", I've added some "Wait Until..." functionality.

This had caused the error that you can view below.

What is the correct approach for managing test dependencies?

testAll.dart

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'common_integration_test.dart';
import 'testOne.dart' as test1;
import 'testTwo.dart' as test2;

main() {
  testAll();
}

Future<void> testAll() async {
  group('TestAll :', () {
    test1.testOne();
  });
  await waitUntilDone(() => test1.isCompleted == true);
  test2.testTwo();
}

testOne.dart

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'common_integration_test.dart';

bool isComplet = false;
get isCompleted => isComplet;
main() {
  testOne();
}

Future<void> testOne() async {
  group('TestOne :', () {
    testWidgets("TestOne", (WidgetTester tester) async {
      print("testOne");
      isComplet = true;
    });
  });
}

testTwo.dart

 import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'common_integration_test.dart';

main() {
  testTwo();
}

// bool? isComplete;
// set setisComplete(bool link) => isComplete = link;

Future<void> testTwo() async {
  group('TestTwo :', () {
    testWidgets("TestTwo", (WidgetTester tester) async {
      print("testTwo");
    });
  });
}

When trying to run the test, this is what I get: Unhandled Exception: Bad state: Can't call group() once tests have begun running.

This is the full console details:

Restarted application in 7,248ms.
I/flutter ( 5260): 00:00 +0: TestAll : TestOne : TestOne
I/flutter ( 5260): testOne
E/flutter ( 5260): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: Can't call group() once tests have begun running.
E/flutter ( 5260): #0      Declarer._checkNotBuilt
package:test_api/…/backend/declarer.dart:343
E/flutter ( 5260): #1      Declarer.group
package:test_api/…/backend/declarer.dart:236
E/flutter ( 5260): #2      group
package:flutter_test/src/test_compat.dart:189
E/flutter ( 5260): #3      testTwo
integration_test\testTwo.dart:15
E/flutter ( 5260): #4      testAll
integration_test\testAll.dart:17
E/flutter ( 5260): <asynchronous suspension>
E/flutter ( 5260):
I/flutter ( 5260): 00:04 +1: All tests passed!
W/com.xxxx( 5260): Reducing the number of considered missed Gc histogram windows from 241 to 100
0

There are 0 answers