https://flutter.dev/docs/cookbook/testing/unit/introduction
上記ページにあるユニットテストのサンプルをそのまま動かしてみようとしているのですが、
実行するとエラーが出ます。
flu_basic/ lib/ main.dart test/ counter_test.dart
//main.dart class Counter { int value = 0; void increment() => value++; void decrement() => value--; }
//counter_test.dart import 'package:test/test.dart'; import 'package:flu_basic/main.dart'; void main() { group('Counter????', () { test('value should start at 0', () { expect(Counter().value, 0); }); test('value should be incremented♉️', () { final counter = Counter(); counter.increment(); expect(counter.value, 1); }); test('value should be decremented????', () { final counter = Counter(); counter.decrement(); expect(counter.value, -1); }); }); }
//pubspec.yamlのdev_dependenciesの部分 dev_dependencies: test: ^1.15.3
これでandroid studioのterminalで
flutter test test/counter_test.dart
を実行すると、
Running "flutter pub get" in flu_basic... 0.6s 00:00 +0: loading /Users/userno1/dev2/flu_basic/test/counter_test.dart Error: cannot run without a dependency on "package:flutter_test". Ensure the following lines are present in your pubspec.yaml: dev_dependencies: flutter_test: sdk: flutter 00:00 +0 -1: loading /Users/userno1/dev2/flu_basic/test/counter_test.dart [E] Failed to load "/Users/userno1/dev2/flu_basic/test/counter_test.dart": Compilation failed Test: /Users/userno1/dev2/flu_basic/test/counter_test.dart Shell: /Users/userno1/dev2/flutter/bin/cache/artifacts/engine/darwin-x64/flutter_tester 00:00 +0 -1: Some tests failed.
上記のようなエラーが出ます。
pubspec.yamlのdev_dependencies:の部分を
dev_dependencies: #test: ^1.15.3 ←コメントアウト flutter_test: sdk: flutter
上記のようにすると
00:00 +0: loading /Users/userno1/dev2/flu_basic/test/counter_test.dart Error: Could not resolve the package 'test' in 'package:test/test.dart'. test/counter_test.dart:4:8: Error: Not found: 'package:test/test.dart' import 'package:test/test.dart'; ^ 00:02 +0: loading /Users/userno1/dev2/flu_basic/test/counter_test.dart test/counter_test.dart:10:7: Error: Method not found: 'expect'. expect(Counter().value, 0); ^^^^^^ test/counter_test.dart:9:5: Error: Method not found: 'test'. test('value should start at 0', () { ^^^^ test/counter_test.dart:18:7: Error: Method not found: 'expect'. expect(counter.value, 1); ^^^^^^ test/counter_test.dart:13:5: Error: Method not found: 'test'. test('value should be incremented♉️', () { ^^^^ test/counter_test.dart:26:7: Error: Method not found: 'expect'. expect(counter.value, -1); ^^^^^^ test/counter_test.dart:21:5: Error: Method not found: 'test'. test('value should be decremented????', () { ^^^^ test/counter_test.dart:8:3: Error: Method not found: 'group'. group('Counter????', () { ^^^^^ 00:06 +0 -1: loading /Users/userno1/dev2/flu_basic/test/counter_test.dart [E] Failed to load "/Users/userno1/dev2/flu_basic/test/counter_test.dart": Compilation failed Test: /Users/userno1/dev2/flu_basic/test/counter_test.dart Shell: /Users/userno1/dev2/flutter/bin/cache/artifacts/engine/darwin-x64/flutter_tester 00:06 +0 -1: Some tests failed.
上記のエラーが出ました。
多分上記ページの
- Add the test dependency
の部分の問題だと思うのですが、どうすればいいのかわかりません。
どこが問題でしょうか?
2020/8/24/11:49追記
探していたら
https://qiita.com/sekitaka_1214/items/3252140671a6ea200991
上記のページが見つかったのですが、読んでも結局どうなのかよくわかりません。
結局テストできないんでしょうか?
以下flutter doctorの結果です。
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G73, locale ja-JP) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 11.6) [✓] Android Studio (version 4.0) [✓] Android Studio (version 4.0) [✓] Connected device (2 available)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/28 01:35