我写了一些飞镖测试代码:
#import("dart:unittest");
main() {
test('this is a test', () {
int x = 2+3;
expect(x).equals(5);
});
}
在飞镖编辑器中没有显示任何错误,但是当我按下“运行”按钮时,它会报告:
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");
^
我看到我的dart-sdk中有一个“dart:unittest”库。为什么不能运行?
答案 0 :(得分:7)
不幸的是,unittest库尚未连接到dart:namespace。在此之前,如果发生这种情况,您将需要使用相对路径来访问unittest库。
类似的东西:
#import('path-to-dart/lib/unittest/unitest.dart');
答案 1 :(得分:1)
此页面一直显示在dart
和unittest
的Google搜索结果中,所以我想我会添加更新。现在可以通过Dart的包管理器unittest
轻松安装pub
库。为此,请确保:
在创建新的Dart应用程序时检查Add pub support
。
然后在unittest
文件中添加(或取消注释)pubspec.yaml
包的依赖项。该文件应如下所示:
name: range
description: A sample application
dependencies:
unittest: { sdk: unittest }
运行pub install
(尽管如果您使用Dart编辑器,此命令应自动为您运行)。然后,在您要编写测试的文件中,
添加此导入声明:
import "package:unittest/unittest.dart";
你应该好好去。