Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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 颤振:比较两个对象并获得错误:预期:VenuesDetails:<;VenuesDetails>;单元测试_Unit Testing_Flutter_Equatable - Fatal编程技术网

Unit testing 颤振:比较两个对象并获得错误:预期:VenuesDetails:<;VenuesDetails>;单元测试

Unit testing 颤振:比较两个对象并获得错误:预期:VenuesDetails:<;VenuesDetails>;单元测试,unit-testing,flutter,equatable,Unit Testing,Flutter,Equatable,我使用Equatable在单元测试中比较2个对象。这是我从Equatable扩展而来的对象: import 'dart:convert'; import 'package:equatable/equatable.dart'; class VenuesDetails extends Equatable { Response response; VenuesDetails({ this.response, }); factory VenuesDetails.fromJ

我使用Equatable在单元测试中比较2个对象。这是我从Equatable扩展而来的对象:

import 'dart:convert';

import 'package:equatable/equatable.dart';

class VenuesDetails extends Equatable {
  Response response;

  VenuesDetails({
    this.response,
  });

  factory VenuesDetails.fromJson(Map<String, dynamic> json) => VenuesDetails(
        response: Response.fromJson(json["response"]),
      );

  Map<String, dynamic> toJson() => {
        "response": response.toJson(),
      };

  @override
  List<Object> get props => [response];
}

class Response extends Equatable {
  Venue venue;

  Response({
    this.venue,
  });

  factory Response.fromJson(Map<String, dynamic> json) => Response(
        venue: Venue.fromJson(json["venue"]),
      );

  Map<String, dynamic> toJson() => {
        "venue": venue.toJson(),
      };

  @override
  List<Object> get props => [venue];
}

class Venue extends Equatable {
  String id;
  String name;
  Contact contact;
  Location location;
  String canonicalUrl;
  List<Category> categories;
  int createdAt;
  String shortUrl;
  String timeZone;

  Venue({
    this.id,
    this.name,
    this.contact,
    this.location,
    this.canonicalUrl,
    this.categories,
    this.createdAt,
    this.shortUrl,
    this.timeZone,
  });

  factory Venue.fromJson(Map<String, dynamic> json) => Venue(
        id: json["id"],
        name: json["name"],
        contact: Contact.fromJson(json["contact"]),
        location: Location.fromJson(json["location"]),
        canonicalUrl: json["canonicalUrl"],
        categories: List<Category>.from(
            json["categories"].map((x) => Category.fromJson(x))),
        createdAt: json["createdAt"],
        shortUrl: json["shortUrl"],
        timeZone: json["timeZone"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
        "contact": contact.toJson(),
        "location": location.toJson(),
        "canonicalUrl": canonicalUrl,
        "categories": List<dynamic>.from(categories.map((x) => x.toJson())),
        "createdAt": createdAt,
        "shortUrl": shortUrl,
        "timeZone": timeZone,
      };

  @override
  List<Object> get props => [
        id,
        name,
        contact,
        location,
        canonicalUrl,
        categories,
        createdAt,
        shortUrl,
        timeZone,
      ];
}

class Category extends Equatable {
  String id;
  String name;
  String pluralName;
  String shortName;
  Icon icon;
  bool primary;

  Category({
    this.id,
    this.name,
    this.pluralName,
    this.shortName,
    this.icon,
    this.primary,
  });

  factory Category.fromJson(Map<String, dynamic> json) => Category(
        id: json["id"],
        name: json["name"],
        pluralName: json["pluralName"],
        shortName: json["shortName"],
        icon: Icon.fromJson(json["icon"]),
        primary: json["primary"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
        "pluralName": pluralName,
        "shortName": shortName,
        "icon": icon.toJson(),
        "primary": primary,
      };

  @override
  List<Object> get props => [
        id,
        name,
        pluralName,
        shortName,
        icon,
        primary,
      ];
}

class Icon extends Equatable {
  String prefix;
  String suffix;

  Icon({
    this.prefix,
    this.suffix,
  });

  factory Icon.fromJson(Map<String, dynamic> json) => Icon(
        prefix: json["prefix"],
        suffix: json["suffix"],
      );

  Map<String, dynamic> toJson() => {
        "prefix": prefix,
        "suffix": suffix,
      };

  @override
  List<Object> get props => [
        prefix,
        suffix,
      ];
}

class Contact extends Equatable {
  Contact();

  factory Contact.fromJson(Map<String, dynamic> json) => Contact();

  Map<String, dynamic> toJson() => {};

  @override
  List<Object> get props => [];
}

class Location extends Equatable {
  double lat;
  double lng;
  List<LabeledLatLng> labeledLatLngs;
  String cc;
  String country;
  List<String> formattedAddress;

  Location({
    this.lat,
    this.lng,
    this.labeledLatLngs,
    this.cc,
    this.country,
    this.formattedAddress,
  });

  factory Location.fromJson(Map<String, dynamic> json) => Location(
        lat: json["lat"].toDouble(),
        lng: json["lng"].toDouble(),
        labeledLatLngs: List<LabeledLatLng>.from(
            json["labeledLatLngs"].map((x) => LabeledLatLng.fromJson(x))),
        cc: json["cc"],
        country: json["country"],
        formattedAddress:
            List<String>.from(json["formattedAddress"].map((x) => x)),
      );

  Map<String, dynamic> toJson() => {
        "lat": lat,
        "lng": lng,
        "labeledLatLngs":
            List<dynamic>.from(labeledLatLngs.map((x) => x.toJson())),
        "cc": cc,
        "country": country,
        "formattedAddress": List<dynamic>.from(formattedAddress.map((x) => x)),
      };

  @override
  List<Object> get props => [
        lat,
        lng,
        labeledLatLngs,
        cc,
        country,
        formattedAddress,
      ];
}

class LabeledLatLng extends Equatable {
  String label;
  double lat;
  double lng;

  LabeledLatLng({
    this.label,
    this.lat,
    this.lng,
  });

  factory LabeledLatLng.fromJson(Map<String, dynamic> json) => LabeledLatLng(
        label: json["label"],
        lat: json["lat"].toDouble(),
        lng: json["lng"].toDouble(),
      );

  Map<String, dynamic> toJson() => {
        "label": label,
        "lat": lat,
        "lng": lng,
      };

  @override
  List<Object> get props => [
        label,
        lat,
        lng,
      ];
}
但在
expect中(结果、地点)我得到了这个错误:

 getVenuesDetails should perform a get request when the response code is 200 (success):

ERROR: Expected: VenuesDetails:<VenuesDetails>
  Actual: VenuesDetails:<VenuesDetails>

package:test_api                                            expect
package:flutter_test/src/widget_tester.dart 234:3           expect
test/repository/foursquare_repository_impl_test.dart 110:9  main.<fn>.<fn>
响应代码为200(成功)时,getVenuesDetails应执行get请求: 错误:应为:VenuesDetails: 实际:静脉详细信息: 包:test_api expect 包装:颤振测试/src/widget测试仪。dart 234:3预期 test/repository/foursquare_repository_impl_test.dart 110:9 main。。

我使用
equalable
的错误在哪里?

引自pub.dev上的软件包页面:

注意:Equatable仅用于不可变对象,因此所有 成员变量必须是final(这不仅仅是 Equatable-使用可变值重写哈希代码可能会中断 基于散列的集合)

我注意到您的字段不是最终字段,因此这可能打破了平等性

请将标题更改为“使用EqualataBale比较对象不起作用”,因为这会提供更多信息,而且网站不允许我提交编辑
 getVenuesDetails should perform a get request when the response code is 200 (success):

ERROR: Expected: VenuesDetails:<VenuesDetails>
  Actual: VenuesDetails:<VenuesDetails>

package:test_api                                            expect
package:flutter_test/src/widget_tester.dart 234:3           expect
test/repository/foursquare_repository_impl_test.dart 110:9  main.<fn>.<fn>