寻找与 Nashorn 的 jjs 解释器一起使用的 javascript 单元测试套件

Looking for a javascript unit-testing suite to be used with Nashorn's jjs interpreter

Nashorn 的 jjs 解释器允许执行许多复杂的任务,例如创建 Web 服务器、数据库操作和 swing/javafx 接口。这种方法的最大好处是可以进行快速实验,并且能够使用您能想到的任何 java 库。

我在纯 java脚本模式下使用 Nashorn,即:

一切顺利。然而,我无法使标准 java 脚本单元测试套件与 Nashorn 的 jjs 一起工作。

我查看了 jasmine、qunit、mocha 和许多其他框架,但没有得到有效结果。我什至尝试让 java junit 使用纯 jjs 脚本。

其中很多都有 js 测试 运行我在 Web 客户端上发现请求 运行ning,这超出了我的范围。

我希望能够 运行 一个真正的 不可知论者 java 在纯 js 模式下使用 Nashorn jjs 解释器的脚本测试套件,而不是 java模式。

是否有这样的工具,如果有,如何与 Nashorn 的 jjs 一起使用?


更新:

根据 Sirko 的回答,我设法用这 2 个代码片段模仿了预期的行为(警告:Nashorn 的细节在里面)

qunit-nashorn.js:

load("qunit-1.18.0.js");

with(QUnit) {
  init();
  log(function(d) {
    if (!d.result) {
      var message = d.name + "\tFAIL" + d.source;
      message += " actual: " + d.actual + " <> expected: " + d.expected;
      print(message);
    }
  });
  done(function(d) {
    print("time:\t",d.runtime,"ms");
    print("total:\t",d.total);
    print("passed:\t",d.passed);
    print("failed:\t",d.failed);
  });
}

qunit_poc.js:

load("qunit-nashorn.js");

with(QUnit) {
  test("test1", function(a) { a.equal(true,true); });
  test("test2", function(a) { a.equal(false,true); });
}

QUnit.load();

并且 运行使用纯 jjs 处理这些结果如下:

> jjs qunit_poc.js

test2   FAIL    at <anonymous> (qunit_poc.js:5) actual: false <> expected: true
time:    355 ms
total:   2
passed:  1
failed:  1

这是我的一些代码的摘录,我不久前使用它从测试运行中获得 QUnit return 自定义输出:

QUnit.init();

// (failed) tests
QUnit.log( function(details) {} );

// module start
QUnit.moduleStart( function( details ){} );

// module summary
QUnit.moduleDone( function( details ){} );

// test begin
QUnit.testStart( function( details ){} );

// test end
QUnit.testDone( function( details ){} );

// finished all testing
QUnit.done( function(){} );

使用那些 functions/callbacks/event 监听器,我设置了 QUnit 测试的自定义输出。实际测试是这样添加的:

// start module
QUnit.module( 'myModuleName' );

// some tests
QUnit.test( 'some test', function( assert ) { } );

// execute
QUnit.load();

此代码相当陈旧,因此 QUnit 可能提供了一种更简单的方法来执行此操作,但这曾经对我有用。