Flutter integration testing: can I start the test on any page? How?

Viewed 345

So I am testing an app that has multiple pages.

Sometimes, I just want to start a test from a page of choice.

However, I can't figure out how to do it.

Everywhere I look, everyone always starts their integration test at the beginning by calling main().

This makes sense but my case is unique. I tried to import the page that I want to start at and I tried calling the main class but I get the following error:

The constructor returns type 'dynamic' that isn't of expected type 'widget'.

My stack also states:

When the exception was thrown, this was the stack:
#4      main.<anonymous closure>.<anonymous closure> (file:///D:/WEBDEV/EndevStudios/MedicalApp/gshDevWork/medical-app-frontend/integration_test/basic_app_test.dart:94:7)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

I think the class I'm trying to call isn't built that way. Here's the beginning part of that code:


class WelcomePage extends StatelessWidget {
  final String title = "Welcome!";
  final String titleDev = "Take Control of your Health!";
  final String boxDescription =
      "It is for information purposes only and help you access health professionals through virtual means as well as screen for a selection of diseases.";
  final String innerContainerTextTitle =
      "WARNING! This application is not a diagnosing tool.";
  final String descriptionTitle = 'App Features:';
  final String descriptionTitle1 =
      "Technology to analyze a selection of diseases.";
    final String descriptionTitle2 =
      "Resources to learn about different types of diseases; typical treatments; and management standards.";
  final String _titleImagePath = 'assets/appbar/diagnosis.webp';
  WelcomePage();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: _buildAppbar(context),
      body: Container(
          width: displayWidth(context),
          height: displayHeight(context),
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              // _logoImage(context),
              _welcomeInfo(context),
            ],
          )),
    );
  }

In my test I was calling app.WelcomePage();

1 Answers

integration_test will be used to run Screen/Page/Widget. This can be performed by using pumpWidget method.

pumpWidget: Renders the UI from the given [widget]. so anything can be drawn on screen and tested.

Example:

testWidgets('Welcome Page Test', (WidgetTester tester) async {
    /// Build our app and trigger a frame.
    
      await tester.pumpWidget(const WelcomePage());

   ///...
 });
Related