I write some dart test code:
#import("dart:unittest");
main() {
test('this is a test', () {
int x = 2+3;
expect(x).equals(5);
});
}
It doesn't display any error in dart editor, but when I press the "run" button, it reports:
Do not know how to load 'dart:unittest''file:///home/freewind/dev/dart/editor
/samples/shuzu.org/test/model_test.dart':
Error: line 1 pos 1: library handler failed
#import("dart:unittest");
^
I see there is a "dart:unittest" library in my dart-sdk. Why it can't be run?
Unfortunately, the unittest library is not yet wired into the dart: namespace. Until that happens, if it ever happens, you'll need to use a relative path to get to the unittest library.
Something like:
#import('path-to-dart/lib/unittest/unitest.dart');
More examples are here: http://api.dartlang.org/unittest.html
This page keeps showing up in Google results for dart
and unittest
, so I thought I would add an update. The unittest
library is now installed quite easily through pub
, Dart's package manager. To do this, make sure that you:
check Add pub support
when you create a new Dart application.
Then add (or uncomment) the dependency for the unittest
package in your pubspec.yaml
file. That file should look like this:
name: range
description: A sample application
dependencies:
unittest: { sdk: unittest }
Run pub install
(although if you are using Dart Editor, this command should automatically get run for you). Then, in the file where you will be writing your tests,
add this import declaration:
import "package:unittest/unittest.dart";
And you should be good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With