簡體   English   中英

如何為網絡項目設置單元測試

[英]how to setup a unittest for a web-project

我在DartEditor(1.8.5)中正確配置我的第一個單元測試時遇到問題。

我用位於Web文件夾中的Dart編寫了一個Web應用程序。 現在,我添加了一個與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() {...}

不幸的是,我現在在運行此測試文件時遇到問題。

  • 與Dartium一起運行會導致出現以下消息: 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';

使用useVMConfiguration()代替useHtmlConfiguration()沒有幫助。 測試執行仍然抱怨import 'dart:html'; 在被測庫中。

“使用Dart進行單元測試”文章中找不到解決方案。

更新(包含GünterZöchbauer的評論)

好的,我創建了調用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

您需要使用測試腳本作為腳本標記創建網頁index.html ,並像任何Dart Web應用程序一樣啟動它。 您還可以使用content_shell非交互地運行它。 Dart SDK包含一個批處理腳本,該腳本可下載並安裝content_shell (SDK下載中不包含此腳本,以保持合理的下載大小。

http://pub.dartlang.org上還有一個test_runner軟件包,可幫助運行test目錄中的所有測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM