单元测试 – 如何让content_shell运行我的测试?

对于这已有问题已有答案,但我认为这是一个新的东西.我正在尝试让drone.io在content_ shell中运行我的测试.我按照说明启动了X服务器.通过download_contentshell.sh脚本下载了content_shell.并根据我从这里找到的答案和其他来源获得的说明执行content_shell.问题是它们都不起作用. content_shell不会运行我的测试,除非我给它一个绝对文件路径,但如果我这样做,当它运行测试时,它会失败,因为它不能使用所需的导入.以下是我在drone.io设置中运行测试脚本的操作

sudo start xvfb
pub install
test/run.sh

这是run.sh脚本

#!/bin/bash

which content_shell
if [[ $? -ne 0 ]]; then
    $DART_SDK/../chromium/download_contentshell.sh
    unzip content_shell-linux-x64-release.zip

    cs_path=$(ls -d drt-*)
    PATH=$cs_path:$PATH
fi

results=$(content_shell --args --dump-render-tree test/index.html 2>&1)
echo -e "$results"

# check to see if DumpRenderTree tests
# fails,since it always returns 0
if [[ "$results" == *"Some tests Failed"* ]]
then
    exit 1
fi

if [[ "$results" == *"Exception: "* ]]
then
    exit 1
fi

这是飞镖测试文件

import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'dart:html';
import 'dart:async';
import 'package:polymer/polymer.dart';

main() {
  // Ensure polymer is looking for bound variables...
  addXParent();
  initpolymer();
  removeXParent();

  setUp(addXParent);
  tearDown(removeXParent);

  group("encountermap",(){
    test('has canvas element',(){
      new Timer(
        new Duration(milliseconds: 2500),expectAsync0((){
          expect(
            querySelector('encounter-map').shadowRoot.querySelector('canvas'),isNotNull
          );
        })
      );
    });

    test("contains file input element",expectAsync0((){
          expect(
            querySelector('encounter-map').shadowRoot.querySelector('input'),isNotNull
          );
          expect(
              querySelector('encounter-map').shadowRoot.querySelector('input'),new isinstanceOf<FileUploadInputElement>()
          );
          expect(
            querySelector('encounter-map').shadowRoot.querySelector('input').attributes['type'],contains('file')
          );
        })
      );
    });
  });
}

addXParent() {
  document.body.append(createElement('<encounter-map></encounter-map>'));
}

removeXParent() {
  querySelectorAll('encounter-map').forEach((el)=> el.remove());
}

createElement(String html) =>
  new Element.html(html,treeSanitizer: new NullTreeSanitizer());

class NullTreeSanitizer implements NodeTreeSanitizer {
  void sanitizeTree(node) {}
}

和index.html文件

<head>
<!-- Load component(s) -->
<link rel="import" href="packages/RPGHelper/encountermap.html">
<script type="application/dart" src="test.dart"></script>
<script src="packages/unittest/test_controller.js"></script>
</head>

我已经看过这个测试正在运行,所有发生的事情是content_shell没有退出,停止脚本完成,从而超时.您可以找到此项目的完整来源here

这真的让我起了作用.这是一个错误吗?如果它有所作为我使用的飞镖版本是“Dart SDK版本1.1.0-dev.4.0”

此测试在“Dart编辑器版本1.1.0.dev_04_00(DEV)”中运行完美,而不是在使用content_shell时

解决方法

在向Chris Strom询问之后我就开始工作了.看来我没有使用以下内容

useHtmlConfiguration(true);

看起来很傻,因为我很确定我在其他地方看到了这个.你还需要确保,我一直在做的事情

import 'package:unittest/html_config.dart';

已经完成,因为那就是

useHtmlConfiguration(true);

来自.这将确保在所有测试完成后发送正确的信号以关闭窗口.现在我的DroneIO测试通过:-)

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...