【问题标题】:drone.io headless dartium testingdrone.io 无头 dartium 测试
【发布时间】:2013-10-28 21:22:50
【问题描述】:

您可以在drone.io 上为 Dart 运行基于浏览器的单元测试吗?我最后一次失败的构建是here。我尝试了sudo start xvfb,但我不确定如何将其指向启动单元测试的 index.html 文件,有人知道该怎么做吗?我应该说我对任何实际的 DOM 测试毫无兴趣,但我的库导入了 'dart:html' 所以我不能在基本的 dart vm only 配置中运行它。

【问题讨论】:

    标签: unit-testing automated-tests dart


    【解决方案1】:

    更新:修改了构建脚本以下载 content_shell。还更新了跳转任务createUnitTestTask()中content_shell的路径。


    我使用hop pub package 对无人机进行无头测试。相对简单的例子可以参考simplot库。但这些步骤基本上是将以下内容添加到您的pubspec.yaml 作为开发人员依赖项:

    hop: '>=0.27.0'
    unittest: '>=0.9.0 <0.10.0'
    

    在您的项目根目录中创建一个工具目录并添加一个文件hop_runner.dart。我的看起来像这样:

    library dumprendertree;
    
    import 'package:hop/hop.dart';
    import 'dart:io';
    import 'dart:async';
    
    main(List<String> args) {
      addTask('test', createUnitTestTask());
      runHop(args);
    }
    
    Task createUnitTestTask() {
      return new Task((TaskContext tcontext) {
        tcontext.info("Running Unit Tests....");
        var result = Process.run('./content_shell',
            ['--dump-render-tree','test/simplot_tests.html'])
            .then((ProcessResult process) {
              tcontext.info(process.stdout);
            });
        return result;
      });
    }
    

    您可以在测试目录中看到它在哪里调用我的simplot_tests.html 文件。

    那么我的无人机脚本是:

    $DART_SDK/../chromium/download_contentshell.sh
    unzip content_shell-linux-x64-release.zip
    mv drt*/* .
    pub get
    sudo start xvfb
    dart --checked tool/hop_runner.dart test
    

    simplot_tests.html 文件如下所示:

    <!DOCTYPE html>
    
    <html>
      <head>
        <title>Unit Tests for Simplot Library</title>
      </head>
      <body>
        <script type="text/javascript" src="packages/unittest/test_controller.js"></script>
        <script type="text/javascript" src="packages/browser/dart.js"></script>
        <script type="application/dart" src="simplot_tests.dart"></script>
      </body>
    </html>
    

    最后,dart 文件看起来像这样:

    import 'package:simplot/simplot.dart';
    import 'package:unittest/unittest.dart';
    import 'package:unittest/html_enhanced_config.dart';
    import 'dart:html';
    import 'dart:math';
    
    part 'tests/logarithmic_tests.dart';
    part 'tests/time_stamp_tests.dart';
    part 'tests/axis_configure_tests.dart';
    part 'tests/create_single_plot.dart';
    part 'tests/create_multiple_plots.dart';
    part '../lib/src/axis_config.dart';
    
    void main() {
      print('Running unit tests for simplot library.');
      useHtmlEnhancedConfiguration();
      group('All Tests:', (){
        test('test of logarithmic functions', () => logarithmicTests());
        test('test of time stamp', () => timeStampTests());
        test('test of axis configuration', () => axisConfigTests());
        test('test of creating a single plot', () => createSinglePlot());
        test('test of creating multiple plots', () => createMultiplePlots());
      });
    }
    

    希望这能让你开始。

    【讨论】:

    • 当我从项目的根目录运行您的示例时(dart --checked tool/hop_runner.dart test)我收到以下错误:测试:ProcessException:没有这样的文件或目录命令:content_shell - -dump-render-tree test/simplot_tests.html 任务未完成 - 异常(81)
    • 测试目录中有 simplot_tests.html 文件吗?我只是在我的机器上本地运行它,它工作正常,在无人机上也能正常工作。我只是不确定你说运行你的样本是什么意思。理想情况下,您希望修改您自己的 tests.html 文件的答案中的路径。
    • 我认为可能是 Content_shell 与 Mavericks 的问题,为什么该示例不适合我。我得到: CFAllocator 的内部未知;通过 CFAllocator 的内存不足故障不会导致终止。 crbug.com/45650.
    • @basheps - 从 0.8.10.8_r30039 开始,Dart SDK 似乎不再包含 content-shell 可执行文件。这会导致您看到的错误(我现在也得到了)。添加,因为 Drone 也不再可以访问 content-shell,它也会在那里失败。如果您有兴趣在 Drone 上使用这种方法,可以投票here
    【解决方案2】:

    这是我的 xml2json 库的 Drone 脚本

    pub install
    sudo start xvfb
    content_shell --args --dump-render-tree test/xml2json.html | sed -n 2p | grep PASS
    

    它使用标准的基于 HTML 的单元测试,即包括 htmlconfiguration()。

    grep 只是检查通过/失败,你可能不需要这个。

    【讨论】:

    • 我试过你的脚本但是失败了,如果我把它改成content_shell --args --dump-render-tree test/xml2json.html那么它工作正常,否则我得到$ content_shell --args --dump-render-tree test/unit/index.html $ sed -n 2p $ grep PASS Xlib: extension "RANDR" missing on display ":0".
    • 我收到以下错误:/home/ubuntu/.build.sh: line 52: content_shell: command not found。如何安装 content_shell 命令?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 2015-11-03
    • 2014-08-02
    • 1970-01-01
    相关资源
    最近更新 更多