1

I am getting following error while running flutter unit test.

00:05 +1: ... /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with --enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine not prepare and launch isolate. Shell: [ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the engine with configuration. 00:05 +1 -1: loading /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart [E] Failed to load "/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart": Shell subprocess cleanly reported an error before connecting to test harness. Check the logs above for an error message. Test: /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/Refund_test.dart Shell: /home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with --enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine not prepare and launch isolate. Shell: [ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the engine with configuration. 00:05 +1 -2: loading /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart [E] Failed to load "/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart": Shell subprocess cleanly reported an error before connecting to test harness. Check the logs above for an error message. Test: /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/LineItem_test.dart Shell: /home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester Shell: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: error: import of dart:mirrors with --enable-mirrors=false Shell: [ERROR:flutter/shell/common/engine.cc(175)] Could not prepare to run the isolate. Shell: [ERROR:flutter/shell/common/engine.cc(122)] Engine not prepare and launch isolate. Shell: [ERROR:flutter/shell/testing/tester_main.cc(199)] Could not launch the engine with configuration. 00:06 +1 -3: loading /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart [E] Failed to load "/home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart": Shell subprocess cleanly reported an error before connecting to test harness. Check the logs above for an error message. Test: /home/kazekage/Projects/flutter/flutter_woocommerce/test/model/util/ShippingLine_test.dart Shell: /home/kazekage/Developement/flutter_linux_v1.2.1-stable/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester

pubsec.yml

name: flutter_woocommerce
description: A new Flutter package project.
version: 0.0.1
author:
homepage:

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  dio: ^2.1.6
  built_value: ^6.6.0
  built_value_generator: ^6.6.0
  built_collection: ^4.2.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  mockito: ^4.0.0
  build_runner: ^1.5.0
  source_gen: ^0.9.4+2

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # To add assets to your package, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
  #
  # For details regarding assets in packages, see
  # https://flutter.io/assets-and-images/#from-packages
  #
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # To add custom fonts to your package, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts in packages, see
  # https://flutter.io/custom-fonts/#from-packages

flutter doctor

[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Linux, locale en_US.UTF-8)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.35.0)
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

Tag.dart

import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:flutter_woocommerce/model/util/Link.dart';

part 'Tag.g.dart';

abstract class Tag implements Built<Tag, TagBuilder> {
  static Serializer<Tag> get serializer => _$tagSerializer;

  int get id;

  String get name;

  String get slug;

  @nullable
  String get description;

  @nullable
  int get count;

  @nullable
  @BuiltValueField(wireName: '_links')
  Link get links;

  Tag._();

  factory Tag([updates(TagBuilder b)]) = _$Tag;
}

Tag_test.dart

import 'package:flutter_test/flutter_test.dart';
import 'dart:convert';
import 'package:built_collection/built_collection.dart';
import 'package:flutter_woocommerce/test_strings.dart';
import 'package:flutter_woocommerce/model/Serializers.dart';
import 'package:flutter_woocommerce/model/Tag.dart';
import 'package:flutter_woocommerce/model/util/Link.dart';

void main() {

  final parsedJson = json.decode(TestStrings.TAG_JSON);
  Tag tag = serializers.deserializeWith(Tag.serializer, parsedJson);

  test('id', () {
    expect(tag.id, 32);
  });

  test('name', () {
    expect(tag.name, 'Telephone');
  });

  test('slug', () {
    expect(tag.slug, 'telephone');
  });

  test('description', () {
    expect(tag.description, '');
  });

  test('count', (){
    expect(tag.count, 0);
  });

  test('_links is Link Object', () {
    expect(tag.links, isInstanceOf<Link>());
  });

  test('_links > self is href[]', () {
    expect(tag.links.self, isInstanceOf<BuiltList<Href>>());
  });

  test('_links > collection is href[]', () {
    expect(tag.links.collection, isInstanceOf<BuiltList<Href>>());
  });

  test('_links > collection > href value', () {
    expect(tag.links.collection.first.href, 'http://paathsala-wp.test/wp-json/wc/v2/products/tags');
  });
}
2
  • 1
    could you post your Flutter unit test? The other details are not relevant for the issue. Do you have any error messages over your IDE? Commented Jun 18, 2019 at 16:56
  • @MarianoZorrilla I have updated the question with the unit test. Commented Jun 18, 2019 at 17:29

2 Answers 2

1

The problem is that you're trying to use reflection (dart:mirror), which is not possible with Flutter because:

"Since reflection makes all code implicitly used by default, it interferes with tree shaking." Source

I believe it is related with the JSON serialization provided by the built_value_generator dart package.

Sign up to request clarification or add additional context in comments.

3 Comments

It was working a couple of minutes ago. All the tests were passed, now its not working.
Let's see if we can find a solution. Something had to be changed since then. Did you add or update a package? Or maybe added another code not present in your question? The log you provided tell us that the reason is what I've said.
I haven't updated packages but I wrote some model and tests since last time it ran fine.
1

It seems I have imported a wrong library in one of my model class. Once I removed the library

import 'package:built_collection/built_collection.dart';

All the tests are passing.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.