简体   繁体   English

我如何构建一套Qunit测试,所有测试都有自己的qunit灯具?

[英]How do I build a suite of Qunit tests that all have their own qunit fixtures?

I have two XXXTest.html files, each similar to this: 我有两个XXXTest.html文件,每个都与此类似:

<html>
    <head>
        <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" />
        <script src="../../../public/scripts/common/SomeUtils.js"></script>
    </head>
    <body>
        <div id="qunit"></div>
        <div id="qunit-fixture">
             <div id="findme">Something specific for the code under test</div>
        </div>
        <script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
        <script src="SomeUtilsTest.js"></script>
    </body>
</html>

Each has their own qunit-fixture, so the html file is equivalent to a JUnit Test Class. 每个都有自己的qunit-fixture,所以html文件相当于一个JUnit Test Class。 I realize qunit considers modules as roughly the same thing as a test class, but that's very limiting. 我意识到qunit认为模块与测试类大致相同,但这是非常有限的。

What's the best way to have a master html file that will execute tests within other html files? 拥有一个将在其他html文件中执行测试的主html文件的最佳方法是什么? Or what's the "correct way" to separate out tests that need their own fixtures in the qunit world? 或者在qunit世界中分离出需要自己的灯具的测试的“正确方法”是什么?

I usually have a master runner.html, leave my #qunit-fixture empty and populate the fixture from within my modules' setup method. 我通常有一个master runner.html,让我的#qunit-fixture空,并在我的模块的setup方法中填充灯具。

However if you want to share html its easy to: 但是如果你想分享html很容易:

  1. Store the html in a template (ie some-test-fixture.html) 将html存储在模板中(即some-test-fixture.html)
  2. Load the template using ajax (or requirejs !text ) 使用ajax(或requirejs!text )加载模板

Then you can populate the #qunit-fixture as needed 然后你可以根据需要填充#qunit-fixture

There's a good plugin for this called qunit-composite . 这个名为qunit-composite的插件很好。

"Composite is a QUnit plugin that, when handed an array of files, will open each of those files inside of an iframe, run the tests, and display the results as a single suite of QUnit tests." “Composite是一个QUnit插件,当传递一个文件数组时,将打开iframe中的每个文件,运行测试,并将结果显示为一组QUnit测试。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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