[英]how to setup a unittest for a web-project
I have problems to properly configure my first unittest in the DartEditor(1.8.5). 我在DartEditor(1.8.5)中正确配置我的第一个单元测试时遇到问题。
I wrote a web-app with Dart that is located in the web-folder. 我用位于Web文件夹中的Dart编写了一个Web应用程序。 Now i added a test-folder parallel to web with a file called
test.dart
: 现在,我添加了一个与Web并行的测试文件夹,并带有一个名为
test.dart
的文件:
library dartingflame_test;
import 'dart:math';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:mockito/mockito.dart';
import '../web/dartingflame.dart';
void main() {
useHtmlConfiguration();
test("verify robot's direction after move", verifyRobotDirectionAfterMove);
}
void verifyRobotDirectionAfterMove() {...}
Unfortunatly I now have problems to run this test file. 不幸的是,我现在在运行此测试文件时遇到问题。
Unable to locate associated html file
Unable to locate associated html file
Observatory listening on http://127.0.0.1:49919 The built-in library 'dart:html' is not available on the stand-alone VM. 'package:unittest/html_config.dart': error: line 10 pos 1: library handler failed import 'dart:html';
Observatory listening on http://127.0.0.1:49919 The built-in library 'dart:html' is not available on the stand-alone VM. 'package:unittest/html_config.dart': error: line 10 pos 1: library handler failed import 'dart:html';
Observatory listening on http://127.0.0.1:49919 The built-in library 'dart:html' is not available on the stand-alone VM. 'package:unittest/html_config.dart': error: line 10 pos 1: library handler failed import 'dart:html';
Using useVMConfiguration()
instead of useHtmlConfiguration()
doesn't help. 使用
useVMConfiguration()
代替useHtmlConfiguration()
没有帮助。 The test execution still complaints about the import 'dart:html';
测试执行仍然抱怨
import 'dart:html';
-line in the library under test. 在被测库中。
I couldn't find a solution in the "Unit Testing with Dart" -article. 在“使用Dart进行单元测试”文章中找不到解决方案。
UPDATE (incorporating Günter Zöchbauer's comment) 更新(包含GünterZöchbauer的评论)
ok, i created the index.html which invokes test.dart, but now i seem to have a problem with the relative import of the lib under test import '../web/dartingflame.dart';
好的,我创建了调用test.dart的index.html,但是现在我似乎在测试
import '../web/dartingflame.dart';
的相对导入库中import '../web/dartingflame.dart';
: :
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8081/web/dartingflame.dart
An error occurred loading file: http://localhost:8081
You need to create a web page index.html
with the test script as script tag an launch it like any Dart web app. 您需要使用测试脚本作为脚本标记创建网页
index.html
,并像任何Dart Web应用程序一样启动它。 You can also run it non-interactively using content_shell
. 您还可以使用
content_shell
非交互地运行它。 The Dart SDK contains a batch script which downloads and installs content_shell
(it is left out of the SDK download to keep a reasonable download size. Dart SDK包含一个批处理脚本,该脚本可下载并安装
content_shell
(SDK下载中不包含此脚本,以保持合理的下载大小。
There is also a package test_runner
available at http://pub.dartlang.org which helps running all tests in the test
directory. 在http://pub.dartlang.org上还有一个
test_runner
软件包,可帮助运行test
目录中的所有测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.