Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 695
peopletookallthegoodnames Avatar asked Apr 05 '19 02:04

peopletookallthegoodnames


People also ask

How do you run a dart test?

A single test file can be run just using dart test path/to/test. dart (as of Dart 2.10 - prior sdk versions must use pub run test instead of dart test ). Many tests can be run at a time using dart test path/to/dir . It's also possible to run a test on the Dart VM only by invoking it using dart path/to/test.

What is Flutter_test?

The flutter_test package provides the following tools for testing widgets: The WidgetTester allows building and interacting with widgets in a test environment. The testWidgets() function automatically creates a new WidgetTester for each test case, and is used in place of the normal test() function.


1 Answers

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.

like image 200
peopletookallthegoodnames Avatar answered Oct 23 '22 09:10

peopletookallthegoodnames