Skip to content

Difference between running flutter test and flutter test [path] when loading test resources #33113

@ole-vegard

Description

@ole-vegard

There seems to be a difference between running flutter test and flutter test [path] when it comes to accessing test resources.

Steps to Reproduce

Project structure :

lib/...
test/path_test.dart
test_resources/testfile.txt

testfile.txt just contains an arbitrary string :

This is a test

path_test.dart contains a tests that attempts to load test_resources/testfile.txt :

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('Read file test', (){
      File f = File("test_resources/testfile.txt");
      expect(f.readAsStringSync(),"This is a test");
  })
}

Run using path to test file

lutter test test/path_test.dart
00:01 +1: All tests passed!                                                                                                                                                                                                                                                             

Run using just flutter test

flutter test
00:01 +0 -1: Read file test [E]                                                                                                                                                                                                                                                         
  FileSystemException: Cannot open file, path = 'test_resources/testfile.txt' (OS Error: No such file or directory, errno = 2)
  dart:io              _File.readAsStringSync
  path_test.dart 8:16  main.<fn>
  
00:01 +0 -1: Some tests failed. 

Version :

Flutter 1.5.4-hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7a4c33425d (3 weeks ago) • 2019-04-29 11:05:24 -0700
Engine • revision 52c7a1e849
Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

Running the tests through Android Studio works fine, just the command line command flutter test fails.

Why is there a difference between the commands? Is there a way I can make it work both through my IDE and the flutter test command?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions