简体   繁体   English

Dart 单元测试无法在 Github 上运行

[英]Dart unit tests fail to run on Github Actions

I have a dart project with unit tests.我有一个带有单元测试的 dart 项目。 When I run the unit tests locally they run successfully.当我在本地运行单元测试时,它们运行成功。

I added CI to the project with Github Actions.我使用 Github Actions 将 CI 添加到项目中。 The same unit tests that run successfully locally, fail on Github Actions with the following error:在本地成功运行的相同单元测试在 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 imports foo.dart as a package (not relative path). foo_test.dart 将 foo.dart 导入为 package(不是相对路径)。

import 'package:foo/foo.dart'

The issue was caused due to me renaming the package name in pubspec.yaml and not updating the import in the test file.该问题是由于我在 pubspec.yaml 中重命名 package 名称并且未更新测试文件中的导入而引起的。

pubspec.yaml: pubspec.yaml:

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

...

Either reverting the name change or updating the import to import package:foo_bar/foo.dart fixed the issue on Github Actions.恢复名称更改或更新导入以导入package:foo_bar/foo.dart修复了 Github 操作上的问题。

The weird thing is that regardless of the rename, the tests still ran successfully locally, which makes me think this might be a caching bug.奇怪的是,无论重命名如何,测试仍然在本地成功运行,这让我觉得这可能是一个缓存错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM