【问题标题】:Flutter Integration test: I can't target some of my widgets - Getter not foundFlutter 集成测试:我无法定位我的一些小部件 - 找不到 Getter
【发布时间】:2021-06-24 15:16:05
【问题描述】:

我正在学习 Flutter 中的集成测试,但遇到了问题。

我的应用包含一个登录按钮小部件,我的测试从抽它开始。

但是,我似乎无法定位它。

每次尝试都会导致以下错误:

integration_test/doctor_integration_test.dart:21:24: Error: Getter not found: 'SignInPage'.
    expect(find.byType(SignInPage), findsOneWidget);
                       ^^^^^^^^^^
                                                                        
                                                                        
FAILURE: Build failed with an exception.

SignInPage 在以下范围内被调用:

MaterialApp _buildMaterialApp(BuildContext context) {
    return MaterialApp(
      title: 'Skinopathy: Doctor',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      routes: {
        '/': (context) {
          return BlocListener<AppBloc, AppState>(
            listener: (context, state) {
              if (state is AppAuthenticated) {
                Navigator.pushReplacement(
                  context,
                  MaterialPageRoute(
                    builder: (_) => WelcomePage(),
                  ),
                );
              } else if (state is AppUnauthenticated) {
                Navigator.pushReplacementNamed(context, '/sign_in');
              } else if (state is AppOutdated) {
                Navigator.pushReplacement(
                  context,
                  MaterialPageRoute(
                    builder: (_) => OutdatedVersionPage(),
                  ),
                );
              }
            },
            child: Center(
              child: SplashPage(),
            ),
          );
        },
        '/sign_in': (context) {
          return SignInPage();
        },

我的假设是在加载 SignInPage 之前进行集成。

_buildMaterialApp 也是 Widget _buildRootLevelWidgets(BuildContext context) 的子对象

如何正确定位 SignInPage 进行测试?

还有什么我做错了吗?

请注意:我没有构建这个应用程序;我只是来测试的。

提前致谢!

【问题讨论】:

    标签: flutter dart testing integration-testing


    【解决方案1】:

    我很笨;我忘记导入允许它识别 SignInPage 的相应文件

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 2021-02-04
      • 2021-09-06
      • 1970-01-01
      • 2022-12-12
      • 2022-08-03
      • 2019-02-25
      • 2020-01-16
      • 2021-05-09
      相关资源
      最近更新 更多