Sur*_*gch 23 testing matcher dart flutter
我正在 Flutter 中对渲染对象进行测试。我想检查这样的不平等(简化):
testWidgets('render object heights not equal', (WidgetTester tester) async {
final renderObjectOneHeight = 10;
final renderObjectTwoHeight = 11;
expect(renderObjectOneHeight, notEqual(renderObjectTwoHeight));
});
Run Code Online (Sandbox Code Playgroud)
我编造了,notEqual
因为它不存在。这也不起作用:
!equals
我找到了一个有效的解决方案,所以我在问答风格下发布了我的答案。不过,我欢迎任何更好的解决方案。
Sur*_*gch 45
您可以使用isNot()
来否定equals()
匹配器。
final x = 1;
final y = 2;
expect(x, isNot(equals(y)));
Run Code Online (Sandbox Code Playgroud)
或者如评论中所述:
expect(x != y, true)
Run Code Online (Sandbox Code Playgroud)
这对我来说实际上似乎更具可读性。
归档时间: |
|
查看次数: |
7252 次 |
最近记录: |