I can't run indivual test files in my Dart plugin

2,136

OK so I actually found a solution for this.

In Android studio in the run dropdown you select Edit Configurations
Then you press the + button and select Flutter test
Make sure the Test scope is All in file and point it at your test file.
You can now run the individual test file and also debug it in android studio by selecting this configuration in the run drop-down.

Share:
2,136
peopletookallthegoodnames
Author by

peopletookallthegoodnames

Updated on December 10, 2022

Comments

  • peopletookallthegoodnames
    peopletookallthegoodnames over 1 year

    I'm developing a plugin for Dart and Flutter and I've started with a suite of tests, since it's porting from a java implementation.

    The issue I'm seeing is that I can run all tests, but I can't run a single test file, or debug it.

    I used the Android studio project generator and chose "Flutter Package"

    I belive the issue lies with android studio not recognizing the tests as flutter tests and failing to include the required imports.

    The test code looks like the following;

    import 'package:flutter_test/flutter_test.dart';
    
    void main() {
      test('Test Name', () {
        ///Test cases in here
      });
    }
    

    And the error I'm seeing when trying to run or debug indivual tests are;

    file:///E:/flutter/packages/flutter_test/lib/src/accessibility.dart:8:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui;
           ^
    file:///E:/flutter/packages/flutter_test/lib/src/binding.dart:8:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui;
           ^
    file:///E:/flutter/packages/flutter_test/lib/src/matchers.dart:8:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui;
           ^
    file:///E:/flutter/packages/flutter_test/lib/src/matchers.dart:9:8: Error: Not found: 'dart:ui'
    import 'dart:ui';
           ^
    file:///E:/flutter/packages/flutter_test/lib/src/test_pointer.dart:12:1: Error: Not found: 'dart:ui'
    export 'dart:ui' show Offset;
    ^
    file:///E:/flutter/packages/flutter/lib/src/rendering/binding.dart:8:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui show window;
           ^
    file:///E:/flutter/packages/flutter/lib/src/rendering/box.dart:6:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui show lerpDouble;
           ^
    file:///E:/flutter/packages/flutter/lib/src/rendering/debug_overflow_indicator.dart:6:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui;
           ^
    file:///E:/flutter/packages/flutter/lib/src/rendering/editable.dart:8:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui show TextBox, lerpDouble;
           ^
    file:///E:/flutter/packages/flutter/lib/src/rendering/error.dart:5:8: Error: Not found: 'dart:ui'
    import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextStyle;
           ^
    
    Process finished with exit code 254
    

    Is there some other configuration step I'm missing here, or an alternate to package:flutter_test/flutter_test.dart I should be using here?

    I attempted to swap out the flutter tests with the pure dart ones, but then no tests would even load. The error was;

    Failed to load test harness. Are you missing a dependency on flutter_test?