![](/img/trans.png)
[英]How do I compare two list in expect function of flutter unit testing?
[英]how do I unit test with multiple expect
當有3個期望時,我在下面編寫的單元測試不起作用,我該如何重寫下面的單元測試:
test('400 bad response', () async {
when(
() => sampleClient.getTransaction(
'1'),
).thenThrow(DioError(
response: Response(
statusCode: 400,
data: badRepsonseJson,
requestOptions: RequestOptions(path: '')),
requestOptions: RequestOptions(path: '')));
final call = sampleService.getTransactionByHash(
'1');
expect(() => call, throwsA(TypeMatcher<TatumException>())); // Expect 1
try {
await sampleService.getTransactionByHash(
'1');
} on TatumException catch (e) {
expect(e.errorCode, badResponse.statusCode); // Expect 2
expect(e.message, badResponse.message); // Expect 3
}
});
final call = sampleService.getTransactionByHash( '1'); expect(() => call, throwsA(TypeMatcher<TatumException>())); // Expect 1
我不認為expect
會成功。 調用() => call
只是返回call
變量已經計算的值,不會失敗。
如果您希望sampleService.getTransactionByHash('1');
拋出一個異常,那么你需要在你的回調中調用它來expect
:
expect(
() => sampleService.getTransactionByHash('1'),
throwsA(TypeMatcher<TatumException>()),
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.