Dart 单元测试在 Github 操作上 运行 失败

Dart unit tests fail to run on Github Actions

我有一个带有单元测试的飞镖项目。当我 运行 本地单元测试时,他们 运行 成功。

我使用 Github 操作将 CI 添加到项目中。同一单元测试 运行 在本地成功,在 Github 操作上失败并出现以下错误:

00:00 +0: loading test/foo_test.dart
00:01 +0: loading test/foo_test.dart
00:01 +0 -1: loading test/foo_test.dart [E]
  Failed to load "test/foo_test.dart":
  Couldn't resolve the package 'foo' in 'package:foo/foo.dart'.
  test/foo_test.dart:5:8: Error: Not found: 'package:foo/foo.dart'
  import 'package:foo/foo.dart';
         ^
  test/foo_test.dart:33:26: Error: Method not found: 'Bar'.
      final bar = Bar(
          ^^^^^^^^^^^^

00:01 +0 -1: Some tests failed.
Error: Process completed with exit code 1.

foo_test.dart 将 foo.dart 作为包导入(不是相对路径)。

import 'package:foo/foo.dart'

问题是由于我在pubspec.yaml.

中重命名包名引起的

pubspec.yaml:

name: foo_bar # <---- this was renamed from 'foo' to 'foo_bar'
description: An example dart project
version: 1.0.0

...

对 pubspec.yaml 的任何更改需要 运行 flutter pub get 才能生效 - 包括更改包名称、版本等