繁体   English   中英

Flutter 集成测试:我可以在任何页面上开始测试吗? 如何?

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

所以我正在测试一个有多个页面的应用程序。

有时,我只想从选择的页面开始测试。

但是,我不知道该怎么做。

在我所见的任何地方,每个人总是从一开始就通过调用main()开始他们的集成测试。

这是有道理的,但我的情况是独一无二的。 我尝试导入要开始的页面,并尝试调用主类,但出现以下错误:

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

我的堆栈还指出:

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)

我认为我试图调用的类不是这样构建的。 这是该代码的开头部分:


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),
            ],
          )),
    );
  }

在我的测试中,我调用app.WelcomePage();

integration_test将用于运行 Screen/Page/Widget。 这可以通过使用pumpWidget方法来执行。

pumpWidget:从给定的 [widget] 渲染 UI。 所以任何东西都可以在屏幕上绘制和测试。

例子:

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

   ///...
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM