Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Dart单元测试框架&x27;s'expect'似乎不能正常工作_Unit Testing_Dart - Fatal编程技术网

Unit testing Dart单元测试框架&x27;s'expect'似乎不能正常工作

Unit testing Dart单元测试框架&x27;s'expect'似乎不能正常工作,unit-testing,dart,Unit Testing,Dart,下面是要比较的对象deMapState: class MapState { final Coordinate currentCoordinate; final Iterable<Coordinate> markers; MapState(this.currentCoordinate, this.markers); MapState.empty() : this.currentCoordinate = null, this.markers

下面是要比较的对象de
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;

}
结果(当然是失败):

应为“MapState”的实例

实际值:“MapState”的实例

包:test_api expect

包装:颤振测试/src/widget测试仪。dart 196:3预期

测试/应用程序/映射块测试。dart 25:5主

我将原始测试简化为此,以跟踪错误,因此不要被单元测试的无意义所迷惑

更改
expect(MapState.empty(),MapState.empty())
期望值(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';

注:奇怪的是,将
this.markers=[]
更改为
this.markers=const[]
会有所帮助。胡特???无论如何,
expect([],[])工作。这对我来说毫无意义。

测试失败,因为Dart中的
[]=[]
false
。您可以使用来处理集合相等性。

在我的例子中有帮助。应用于Andrey的case MapState类应该扩展了Equalable。

这完全是胡说八道。为什么
expect([],[])通过和
期望(true,[]=[])没有?x、 xBecause
expect
处理集合并逐元素比较它们。在
expect
方法的文档中甚至没有提到的东西。。。谢谢你的帮助@安德烈·伊利尤宁(AndreyIlyunin)记录在案,尽管是间接的,也不是最清楚的。状态:“
matcher
可以是一个值,在这种情况下,它将被包装在一个matcher中。”
等于
matcher的文档中说:“对于
Iterables
映射
,这将递归地匹配元素。”
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';