飞镖单元测试框架`expect`似乎不能正常工作

问题描述 投票:0回答:1

这是一个比较MapState的对象:

class MapState {
  final Coordinate currentCoordinate;
  final Iterable<Coordinate> markers;

  MapState(this.currentCoordinate, this.markers);

  MapState.empty()
      : this.currentCoordinate = null,
        this.markers = [];

  MapState.withCoordinate(this.currentCoordinate) : this.markers = [];

  MapState.withMarkers(this.markers) : this.currentCoordinate = null;

  MapState newCoordinate(final Coordinate coordinate) =>
      MapState(coordinate, this.markers);

  MapState newMarkersSet(final Iterable<Coordinate> markers) =>
      MapState(this.currentCoordinate, markers);

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
          other is MapState &&
              runtimeType == other.runtimeType &&
              currentCoordinate == other.currentCoordinate &&
              markers == other.markers;

  @override
  int get hashCode =>
      currentCoordinate.hashCode ^
      markers.hashCode;

}

这是单元测试:

test('init, Observer should receive an empty state as a first state',
  () {
    expect(MapState.empty(), MapState.empty());
  });

结果(当然失败):

预期:'MapState'的实例

实际:'MapState'的实例

包:test_api期望

package:flutter_test / src / widget_tester.dart 196:3期待

test / application / map_bloc_test.dart 25:5 main。

我将原始测试简化为跟踪错误,所以不要被单位测试的无意义混淆。

expect(MapState.empty(), MapState.empty());更改为expect(1, 1);会有所帮助,但我无法使用我的对象。

另外,这是我的进口块:

import 'dart:async';

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:taxi/application/map_bloc.dart';
import 'package:taxi/domain/map.dart';

P.S。:奇怪的是,但将this.markers = []改为this.markers = const []会有所帮助。 WUT ???无论如何,expect([], []);工作。这对我没有任何意义。

unit-testing dart
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.