简体   繁体   中英

Dart unit tests fail to run on Github Actions

I have a dart project with unit tests. When I run the unit tests locally they run successfully.

I added CI to the project with Github Actions. The same unit tests that run successfully locally, fail on Github Actions with the following error:

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).

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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