🎉

【Flutter/Test】Notifierクラスを @GenarateNiceMocksでモック化すると、エラーが出る対処法

に公開

はじめに

現在、Flutterエンジニアとして活動しているこっしーです。

1440taskという超シンプルなTODOアプリを開発しています。
(ios)https://apps.apple.com/jp/app/1440task/id1640161652
(android)https://play.google.com/store/apps/details?id=site.studio.ringrininfo.new1440task

実装

Notifierクラスを @GenarateNiceMocksでモック化すると、以下のエラーが出る場合があります。

No method stub was called from within 'when()'. Was a real method called, or perhaps an extension method?

その場合は、自作で以下のようにモックを作成する必要があります。

class MockExample extends Notifier<T> with Mock implements Example {}

こうすると、エラーを回避できると思います

終わり

皆さんも快適なFlutterライフと楽しみましょう!

Discussion