3
votes

My Dart package is currently laid out in the following manner:

lib/
  mypackage.dart
  src/
    mypackage_util.dart
test/
  mypackage_test.dart

Inside mypackage.dart, I'm using the part, part of import strategy to use mypackage_util.dart in mypackage.dart, as recommended by the Pub Layout conventions.

On the test side, I took inspiration from Seth Ladd's example of using unittest, which shows him creating a new library for his tests, which makes sense to me.

Unfortunately, this leads to the inability to import mypackage_util.dart into mypackage_test.dart, which means I can't test classes or functions from mypackage_util.dart, or anything in src/.

The solutions I'm imagining are;

  1. Make mypackage_test.dart a part of the main library, but this seems to make it impossible to just run the test code stand-alone.

  2. Take mypackage_util.dart out of src/, but this seems to imply that you can never unit test src/ code in packages, which seems silly and exposes code I don't want to.

Should I take one of the above approaches, or am I missing something?


Update:

The above situation was due to a library import conflict (see Chapter 2. Dart Tour's Libraries and Visibility section for solutions to library conflicts). See comments below.

1

1 Answers

2
votes

If lib/mypackage.dart declares the library and includes lib/src/mypackage_util.dart using part/part of you just need to include lib/mypackage.dart in your test - or is your problem that you want to test private classes/functions contained in lib/src/mypackage_util.dart?