I'm using the flutter integration driver for flutter mobile automation.
In this regard, I want to understand the recommended approach of calling app.main
in the integration test.
Let's take two below examples:
//imports
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('sanity test suite', () {
//runs before each test
setUp(() async {
SLogger.i('running before test.!');
app.main();
SLogger.i('App opened');
});
testWidgets('sample test', (tester) async {
//some validations
});
testWidgets('check value increments', (tester) async {
//some validations
});
testWidgets('check integration test page', (tester) async {
//some validations
});
});
}
In the above code snippet, I'm calling app.main
in setUp()
method which is executed before each test run. With this, i'm getting below error while executing the second test
I/flutter (18595): The following assertion was thrown running a test:
I/flutter (18595): A FocusManager was used after being disposed of.
I/flutter (18595): Once you have called dispose() on a FocusManager, it can no longer be used.
I/flutter (18595):
Now, let's look into another snippet where I'm calling app.main
in each testWidgets
.
which is perfectly working fine executing all the tests.!
//imports
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('sanity test suite', () {
testWidgets('sample test', (tester) async {
app.main();
// some validations
});
testWidgets('check value increments', (tester) async {
app.main();
// some validations
});
testWidgets('check integration test page', (tester) async { app.main();
// some validations
});
});
}
Which one is the right approach?