简体   繁体   English

如何为网络项目设置单元测试

[英]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. 不幸的是,我现在在运行此测试文件时遇到问题。

  • Run with Dartium leads to the message: Unable to locate associated html file 与Dartium一起运行会导致出现以下消息: Unable to locate associated html file
  • Run leads to: 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM