首页 > 解决方案 > 颤振测试“FrameTimingSummarizer”错误

问题描述

在为颤振启动项目运行颤振测试时,我面临以下问题。

命令 :flutter drive --driver=test_driver/integration_test_driver.dart --target=integration_test/app_test.dart

版本

Flutter:1.20.2(flutter Doctor没有问题),integration_test:1.0.2+2

错误:**flutter/.pub-cache/hosted/pub.dartlang.org/integration_test-1.0.2+2/lib/integration_test.dart:324:11:错误:“FrameTimingSummarizer”不是一种类型。最终 FrameTimingSummarizer frameTimes = ^^^^^^^^^^^^^^^^^^^^ /flutter/.pub-cache/hosted/pub.dartlang.org/integration_test-1.0.2+2/lib /integration_test.dart:302:20:错误:没有为类“IntegrationTestWidgetsFlutterBinding”定义吸气剂“kDebugWarning”。

integration_test_driver.dart

import 'package:integration_test/integration_test_driver.dart';

void main()=> integrationDriver();

app_test.dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'dart:async';
import '../lib/main.dart';

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(MyApp());
    await tester.pumpAndSettle();

    // Verify that our counter starts at 0.
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsNothing);

    // Tap the + icon and trigger a frame.
    await tester.tap(find.byIcon(Icons.add));
    await tester.pump();

    // Verify that our counter incremented.
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsOneWidget);
  });
}


主要.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
    );
  }
}

标签: flutterdartintegration-testingflutter-test

解决方案


I know it's old question and maybe rarely people will face this since the problem lies on the flutter old version, but just for reference in case anyone face this problem in the future,

so here is my "investigation" about integration test, "FrameTimingSummarizer", and flutter version release date,

flutter 1.20.2 : released at Aug 14th, 2020

FrameTimingSummarizer : created at Aug 11th, 2020,
but there are failing check and only migrated to flutter_test at Oct 1st, 2021, so I assume, flutter_test base on flutter 1.20.2 which is released prior to Oct 1st, doesn't have FrameTimingSummarizer class in its library. In fact it seems to be prepared for 1.22.0 and up.

FrameTimingSummarize class history

integration_test : starting 0.9.2 they use FrameTimingSummarize,
so it obvious that flutter 1.20.2 cannot use integration_test 0.9.2, moreover 1.0.2+2 in your configuration.

Conclusion
flutter 1.20.X should use integration_test 0.8.2 at max.
but, if your want to use integration_test 1.0.2+2, please upgrade flutter version to at least 1.22.0. it should solve this problem.

with that being said, I haven't test it my self, and cannot guarantee that there are no other issue about both of the configurations

I hope it can help you in any way, thank you.

EDIT
I have tested the integration_test 0.8.2 route and it work just fine.
I still haven't test the flutter 1.22.0 + integration_test 1.0.2+2 thought

EDIT 2
I have tested the integration_test 0.9.1 and it work fine too.
so this version should be the max instead of 0.8.2


推荐阅读