How do I get 100% code coverage on a main function for an application that looks like this?
lib/main.dart
import 'package:flutter/material.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(body: Center(child: Text('Home Page'))),
);
}
}
test/main_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:example/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
await tester.pumpWidget(MyApp());
// Verify that the init page is the Home Page.
expect(find.text('Home Page'), findsOneWidget);
});
}
--
Recreating code coverage:
$ flutter test --coverage --coverage-path ./coverage/lcov.info
$ genhtml ./coverage/lcov.info -o ./coverage/html
Output
...
Generating output.
Processing file lib/main.dart
Writing directory view page.
Overall coverage rate:
lines......: 66.7% (4 of 6 lines)
functions..: no data found
and the
lcov.info
SF:lib/main.dart
DA:3,0
DA:4,0
...
The only "uncovered" code is:
void main() {
runApp(App());
}
How should I write a test to ensure that this function is covered? Can it be done out-side of an integration test?