Flutter 无法使用 mockito generateMocks 和 json_serializable 生成模拟
Flutter unable to get generate mocks with mockito generateMocks and json_serializable
我正在尝试按照此示例 https://flutter.dev/docs/cookbook/testing/unit/mocking to create http unit tests. I have used json_serializer 在 JSON 和模型之间建立桥梁。我确保这个库启用了空安全
我运行的命令是
flutter pub run build_runner build
并且堆栈跟踪很长而且不会停止,看起来像一个 forever loop
堆栈跟踪中没有我的代码中的确切行,因此不确定从这里到哪里去。
请注意,我没有使用 http 库,因此我给出了 json_serializer 生成的模型
完整的输出在这里,我突出了我认为的主要问题
[INFO] Generating build script...
[INFO] Generating build script completed, took 511ms
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 10.5s
[INFO] There was output on stdout while compiling the build script snapshot, run with `--verbose` to see it (you will need to run a `clean` first to re-snapshot).
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 529ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Running build...
[INFO] Generating SDK summary...
[INFO] 3.3s elapsed, 0/8 actions completed.
[INFO] Generating SDK summary completed, took 3.3s
[INFO] 4.4s elapsed, 4/8 actions completed.
[INFO] 5.4s elapsed, 4/8 actions completed.
[INFO] 13.2s elapsed, 7/8 actions completed.
[SEVERE] json_serializable:json_serializable on test/timeline_vm_test.dart:
***Null check operator used on a null value***
#0 LinkedElementFactory.isLibraryUri (package:analyzer/src/summary2/linked_element_factory.dart:418:48)
#1 LibraryContext.isLibraryUri (package:analyzer/src/dart/analysis/library_context.dart:95:27)
#2 LibraryAnalyzer._isLibrarySource (package:analyzer/src/dart/analysis/library_analyzer.dart:511:25)
#3 LibraryAnalyzer._resolveDirectives (package:analyzer/src/dart/analysis/library_analyzer.dart:552:36)
#4 LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:128:5)
#5 LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:105:12)
#6 AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1590:63)
#7 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#8 AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1565:20)
#9 AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1644:26)
#10 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1266:20)
#11 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2296:24)
<asynchronous suspension>
[INFO] 14.4s elapsed, 8/16 actions completed.
[INFO] 15.5s elapsed, 8/16 actions completed.
[INFO] 16.6s elapsed, 8/16 actions completed.
[INFO] 17.7s elapsed, 8/16 actions completed.
[INFO] 18.7s elapsed, 8/16 actions completed.
[INFO] 19.8s elapsed, 8/16 actions completed.
[INFO] 20.8s elapsed, 8/16 actions completed.
[INFO] 21.9s elapsed, 8/16 actions completed.
[INFO] 22.9s elapsed, 8/16 actions completed.
[INFO] 24.0s elapsed, 8/16 actions completed.
[INFO] 25.1s elapsed, 8/16 actions completed.
[INFO] 26.1s elapsed, 8/16 actions completed.
[INFO] 27.2s elapsed, 8/16 actions completed.
[INFO] 28.3s elapsed, 8/16 actions completed.
[WARNING] No actions completed for 15.0s, waiting on:
- mockito:mockBuilder on test/timeline_vm_test.dart
- mockito:mockBuilder on test/widget_test.dart
- mockito:mockBuilder on lib/busy_notifier.dart
- mockito:mockBuilder on lib/main.dart
- mockito:mockBuilder on lib/data/timeline_vm.dart
.. and 3 more
原来我的情况,我所要做的就是删除
#import '../lib/main.dart'
我不确定具体原因,但确实有效。如果我找到它们,将添加更多详细信息。
我正在尝试按照此示例 https://flutter.dev/docs/cookbook/testing/unit/mocking to create http unit tests. I have used json_serializer 在 JSON 和模型之间建立桥梁。我确保这个库启用了空安全
我运行的命令是
flutter pub run build_runner build
并且堆栈跟踪很长而且不会停止,看起来像一个 forever loop
堆栈跟踪中没有我的代码中的确切行,因此不确定从这里到哪里去。
请注意,我没有使用 http 库,因此我给出了 json_serializer 生成的模型
完整的输出在这里,我突出了我认为的主要问题
[INFO] Generating build script...
[INFO] Generating build script completed, took 511ms
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 10.5s
[INFO] There was output on stdout while compiling the build script snapshot, run with `--verbose` to see it (you will need to run a `clean` first to re-snapshot).
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 529ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Running build...
[INFO] Generating SDK summary...
[INFO] 3.3s elapsed, 0/8 actions completed.
[INFO] Generating SDK summary completed, took 3.3s
[INFO] 4.4s elapsed, 4/8 actions completed.
[INFO] 5.4s elapsed, 4/8 actions completed.
[INFO] 13.2s elapsed, 7/8 actions completed.
[SEVERE] json_serializable:json_serializable on test/timeline_vm_test.dart:
***Null check operator used on a null value***
#0 LinkedElementFactory.isLibraryUri (package:analyzer/src/summary2/linked_element_factory.dart:418:48)
#1 LibraryContext.isLibraryUri (package:analyzer/src/dart/analysis/library_context.dart:95:27)
#2 LibraryAnalyzer._isLibrarySource (package:analyzer/src/dart/analysis/library_analyzer.dart:511:25)
#3 LibraryAnalyzer._resolveDirectives (package:analyzer/src/dart/analysis/library_analyzer.dart:552:36)
#4 LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:128:5)
#5 LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:105:12)
#6 AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1590:63)
#7 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#8 AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1565:20)
#9 AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1644:26)
#10 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1266:20)
#11 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2296:24)
<asynchronous suspension>
[INFO] 14.4s elapsed, 8/16 actions completed.
[INFO] 15.5s elapsed, 8/16 actions completed.
[INFO] 16.6s elapsed, 8/16 actions completed.
[INFO] 17.7s elapsed, 8/16 actions completed.
[INFO] 18.7s elapsed, 8/16 actions completed.
[INFO] 19.8s elapsed, 8/16 actions completed.
[INFO] 20.8s elapsed, 8/16 actions completed.
[INFO] 21.9s elapsed, 8/16 actions completed.
[INFO] 22.9s elapsed, 8/16 actions completed.
[INFO] 24.0s elapsed, 8/16 actions completed.
[INFO] 25.1s elapsed, 8/16 actions completed.
[INFO] 26.1s elapsed, 8/16 actions completed.
[INFO] 27.2s elapsed, 8/16 actions completed.
[INFO] 28.3s elapsed, 8/16 actions completed.
[WARNING] No actions completed for 15.0s, waiting on:
- mockito:mockBuilder on test/timeline_vm_test.dart
- mockito:mockBuilder on test/widget_test.dart
- mockito:mockBuilder on lib/busy_notifier.dart
- mockito:mockBuilder on lib/main.dart
- mockito:mockBuilder on lib/data/timeline_vm.dart
.. and 3 more
原来我的情况,我所要做的就是删除
#import '../lib/main.dart'
我不确定具体原因,但确实有效。如果我找到它们,将添加更多详细信息。