简体   繁体   中英

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:

<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. I realize qunit considers modules as roughly the same thing as a test class, but that's very limiting.

What's the best way to have a master html file that will execute tests within other html files? Or what's the "correct way" to separate out tests that need their own fixtures in the qunit world?

I usually have a master runner.html, leave my #qunit-fixture empty and populate the fixture from within my modules' setup method.

However if you want to share html its easy to:

  1. Store the html in a template (ie some-test-fixture.html)
  2. Load the template using ajax (or requirejs !text )

Then you can populate the #qunit-fixture as needed

There's a good plugin for this called 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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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