flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.36k stars 27.28k forks source link

`flutter test` unable to load dart file in `tests/` on GitHub actions workflows #132292

Closed mhmzdev closed 1 year ago

mhmzdev commented 1 year ago

Is there an existing issue for this?

Steps to reproduce

  1. Write tests for basic API
  2. Run flutter test locally in terminal, the tests will pass
  3. Push the code and create PR, the test will not be able to load file in test/ directory in GitHub actions.

Local Terminal

00:02 +8: All tests passed!   

Expected results

Test must run and pass as expected in the local terminal.

Actual results

This is the log while the action is being executed on GitHub actions.

GitHub Actions log

00:18 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:19 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:20 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:21 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:22 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:23 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:24 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:25 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:26 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:27 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:28 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:29 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:30 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:31 +0: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart                                                                
00:31 +0 -1: loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart [E]                                                         
  Failed to load "/Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart": Compilation failed for testPath=/Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart

To run this test again: /Users/runner/hostedtoolcache/flutter/stable-3.3.10-x64/bin/cache/dart-sdk/bin/dart test /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart -p vm --plain-name 'loading /Users/runner/work/sastaticket-mobile-app/sastaticket-mobile-app/test/data/data_providers/bus_data_provider_test.dart'

Code sample

Workflow file

pull_request_test_run.yaml ```yaml name: Test-Run on: pull_request: types: - opened - ready_for_review branches: - 'dev' paths: - '**.dart' env: flutter_version: "3.3.10" java_version: "12.x" jobs: build: name: Build and Release runs-on: macos-latest steps: - uses: actions/checkout@v2 - name: Cache Flutter dependencies uses: actions/cache@v2 with: path: /Users/runner/hostedtoolcache/flutter key: ${{ runner.OS }}-flutter-install-cache-${{ env.flutter_version }} - name: Setup Flutter uses: subosito/flutter-action@v2 with: flutter-version: ${{ env.flutter_version }} channel: 'stable' - name: Pub Get Packages run: flutter clean && flutter pub get - name: Run unit tests run: flutter test ```

Test File

bus_data_provider_test.dart ```dart import 'package:app_engine/app_engine.dart'; import 'package:dio/dio.dart'; import 'package:mockito/annotations.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sastaticket/configs/configs.dart'; import 'package:sastaticket/cubits/bus/cubit.dart'; import 'package:sastaticket/models/bus/location.dart'; import 'package:sastaticket/models/bus/response/search.dart'; import 'package:sastaticket/models/bus/response/seats.dart'; import 'bus_data_provider_test.mocks.dart'; import '../../helper/client_helper.dart'; @GenerateMocks([Dio]) void main() { group('BusDataProviderTests:', () { final dataLayer = BusDataProvider(dio: ClientHelper.ins); /// test('search(): returns bus search results if a call is success', () async { final mockPayload = { 'origin_city': 'LHE', 'destination_city': 'KHI', 'departure_date': Utils.apiDate(DateTime.now().add(5.days)), }; when( ClientHelper.ins.post( '/v5/affiliates/bus/search', data: mockPayload, ), ).thenAnswer( (_) async => Response( statusCode: 200, data: await BusApiMocks.search(), requestOptions: RequestOptions( path: '/v5/affiliates/bus/search', ), ), ); final resp = await dataLayer.search(mockPayload); expect(resp, isA()); }); test('search(): throws an exception if bus search results call is fail', () async { final mockPayload = { 'origin_city': 'LHE', 'destination_city': 'KHI', 'departure_date': Utils.apiDate(DateTime.now().add(5.days)), }; when( ClientHelper.ins.post( '/v5/affiliates/bus/search', data: mockPayload, ), ).thenThrow(DioError( response: Response( statusCode: 404, data: { 'status': 'failed', }, requestOptions: RequestOptions( path: '/v5/affiliates/bus/search', ), ), requestOptions: RequestOptions( path: '/v5/affiliates/bus/search', ), error: 'No Buses Found', )); try { await dataLayer.search(mockPayload); fail('Expected DioError but got no exception.'); } catch (e) { expect(e, isInstanceOf()); } }); /// test('fetchLocation(): returns a List of cities if the call is success', () async { when( ClientHelper.ins.get('/v2/bus/cities/'), ).thenAnswer( (_) async => Response( statusCode: 200, data: await BusApiMocks.fetchLocations(), requestOptions: RequestOptions( path: '/v2/bus/cities', ), ), ); final resp = await dataLayer.fetchLocations(); expect(resp, isA>()); }); test('fetchLocation(): throws an exception when the cities call fails', () async { when( ClientHelper.ins.get('/v2/bus/cities/'), ).thenThrow(DioError( response: Response( statusCode: 404, data: { 'status': 'failed', }, requestOptions: RequestOptions(path: '/v2/bus/cities/'), ), requestOptions: RequestOptions(path: '/v2/bus/cities/'), error: 'No Cities Found', )); try { await dataLayer.fetchLocations(); fail('Expected DioError but got no exception.'); } catch (e) { expect(e, isInstanceOf()); } }); /// test('seats(): returns seats if the call is success', () async { final client = MockDio(); final dataLayer = BusDataProvider(dio: client); final mockPayload = { "itinerary_id": "864b8c12-df93-4f50-b1c0-1992bed4e26b", "search_query": { "origin_city": "FSB", "destination_city": "RWP", "departure_date": "2022-05-24" }, "itinerary_lookup_key": "BOOKING_LOOKUP_AffiliateBUSES-FSB_RWP_2022-05-24_1653394626.7387655" }; when( client.post( '/v3/bus/seats/', data: mockPayload, ), ).thenAnswer( (_) async => Response( statusCode: 200, data: await BusApiMocks.seats(), requestOptions: RequestOptions( path: '/v3/bus/seats/', ), ), ); final resp = await dataLayer.seats(mockPayload); expect(resp, isA()); }); test('seats(): throws exception for seats if call is failure', () async { final client = MockDio(); final dataLayer = BusDataProvider(dio: client); final mockPayload = { "itinerary_id": "864b8c12-df93-4f50-b1c0-1992bed4e26b", "search_query": { "origin_city": "FSB", "destination_city": "RWP", "departure_date": "2022-05-24" }, "itinerary_lookup_key": "BOOKING_LOOKUP_AffiliateBUSES-FSB_RWP_2022-05-24_1653394626.7387655" }; when( client.post( '/v3/bus/seats/', data: mockPayload, ), ).thenThrow(DioError( response: Response( statusCode: 404, data: { 'status': 'failed', }, requestOptions: RequestOptions(path: '/v3/bus/seats/'), ), requestOptions: RequestOptions(path: '/v3/bus/seats/'), error: 'No Seats Found', )); try { await dataLayer.seats(mockPayload); fail('Expected DioError but got no exception.'); } catch (e) { expect(e, isInstanceOf()); } }); }); } ```

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output ``` [✓] Flutter (Channel stable, 3.7.11, on macOS 13.5 22G74 darwin-arm64, locale en-PK) • Flutter version 3.7.11 on channel stable at /Users/hamza/Development/flutter_3.7.11 • Upstream repository https://github.com/flutter/flutter.git • Framework revision f72efea43c (4 months ago), 2023-04-11 11:57:21 -0700 • Engine revision 1a65d409c7 • Dart version 2.19.6 • DevTools version 2.20.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/hamza/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.81.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.70.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 13.5 22G74 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.170 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```
dam-ease commented 1 year ago

Hi @mhmzdev. Thanks for filing this. Can you try to upgrade and make use of the latest stable release of Flutter and test with a completed and minimal reproducible code sample? If this issue persists, kindly share here your code samples so we could try reproducing this. Thank you!

mhmzdev commented 1 year ago

We have CI/CD for releasing builds to play store and apple store. Both are working fine, only for tests its crashing. If we update this, other needs to be updated as well.

Is there a work-around for now?

FYI: I'm upgrading to latest as well: CC: @dam-ease

dam-ease commented 1 year ago

Hi @mhmzdev. Thanks for responding. Can't point to a workaround for sure now. If the issue still persists after upgrade, kindly provide a completed and minimal reproducible code sample. Thank you

mhmzdev commented 1 year ago

Updating the code base, but its not a minor stuff for us as the app is of prod level and there are a lot of breaking changes. Will reply here in case the issues till persists after updating @dam-ease

mhmzdev commented 1 year ago

There was something wrong with our flutter SDK in the current branch. We changed stuff to default and it's working for current flutter version what we are using.

Closing the ticket @dam-ease

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.