通常の場合 Flutter のテストを実施するには次のコマンドを実行します。
flutter test
この場合は test/ ディレクトリ配下のテストファイルが実行されます。
The test runner considers any file that ends with
_test.dartto be a test file. If you don’t pass any paths, it will run all the test files in yourtest/directory, making it easy to test your entire application at once.
しかし、テストファイルを test/ 以外の別の場所に配置したいケースもあると思います。例えば私は、テストファイルは被テストファイルの隣(=同じディレクトリの中)に配置したい派です。
このように、テストファイルをデフォルトの test/ 以外に配置したときは次のように対象ディレクトリを指定します。これで lib/ 以下の _test.dart ファイルが実行されます。
flutter test lib
A single test file can be run just using
dart test path/to/test.dart(as of Dart 2.10 - prior sdk versions must usepub run testinstead ofdart test).Many tests can be run at a time using
dart test path/to/dir.
参考 #
- Running Tests | Dart Package
- https://pub.dev/packages/test#running-tests