Flutter 测试失败,单元测试预期和实际状态对象相同但仍然失败
Flutter test failure, unit test expected and actual state object are the same but still fail
我有一个这样的代码测试,预期和实际已经有相同的对象,但是单元测试仍然失败,怎么办?
blocTest("_mapClickEmailToState",
wait: const Duration(milliseconds: 500),
build: () {
return bloc;
},
act: (bloc) => bloc.add(ClickEmail()),
expect: () => [
ClickEmailSuccess()
]);
});
我有这个错误
Expected: [Instance of 'ClickEmailSuccess'] Actual: [Instance of
'ClickEmailSuccess'] Which: at location [0] is <Instance of
'ClickEmailSuccess'> instead of <Instance of 'ClickEmailSuccess'>
您必须覆盖 == 运算符和 hashCode 或为此实现 Equatable class。
为了覆盖它们,让我们假设 class 具有属性名称和年龄的人,它看起来像这样:
class Person {
const Person(this.name, this.age);
final String name;
final int age
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Person &&
runtimeType == other.runtimeType &&
name == other.name &&
age == other.age;
@override
int get hashCode => name.hashCode ^ age.hashCode;
}
我有一个这样的代码测试,预期和实际已经有相同的对象,但是单元测试仍然失败,怎么办?
blocTest("_mapClickEmailToState",
wait: const Duration(milliseconds: 500),
build: () {
return bloc;
},
act: (bloc) => bloc.add(ClickEmail()),
expect: () => [
ClickEmailSuccess()
]);
});
我有这个错误
Expected: [Instance of 'ClickEmailSuccess'] Actual: [Instance of 'ClickEmailSuccess'] Which: at location [0] is <Instance of 'ClickEmailSuccess'> instead of <Instance of 'ClickEmailSuccess'>
您必须覆盖 == 运算符和 hashCode 或为此实现 Equatable class。
为了覆盖它们,让我们假设 class 具有属性名称和年龄的人,它看起来像这样:
class Person {
const Person(this.name, this.age);
final String name;
final int age
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Person &&
runtimeType == other.runtimeType &&
name == other.name &&
age == other.age;
@override
int get hashCode => name.hashCode ^ age.hashCode;
}