How to automate unit tests for Windows 8 applications for HTML5?

I am writing an application for Windows 8 and writing block tests for it. How can I run them automatically in a Windows 8 environment?

If I write super-simple JavaScript files, regardless of the Windows 8 or DOM environment, I can unit test them from the command line using Node.js. It is very fast (less than one second).

If I need to enable the DOM, and I use the DOM for not too new functions, I can use jsdom in Node.js and get the same setup and at the same speed.

But jsdom is incomplete, and often I want to use basic Windows 8 features such as the WinJS core library (like WinJS.Promise ) or Windows.* enumerations Windows.* . And ideally, I should test in the same JS engine and in the DOM environment, since my application will really work.

Ideally, I need a test runner: a lightweight container for Windows 8 HTML5 that can run some unit tests with a real DOM and access to the WinJS and Windows Runtime APIs. To integrate into the build process, I also need the ability to report the results back to the command line (stdout, stderr) and change the test runnerโ€™s return code depending on success or failure. And it must be fully automated, possible in the background and very fast (less than 10 seconds).

I know that for WebKit there are tools such as, for example, PhantomJS . Is there such a situation for the Windows Runtime HTML5 environment? If not, which APIs should I look for to create something like this?

+7
source share
1 answer

There is currently no way to run the Win8 / WinJS test suite in a silent way. The runtime environment required for WinJS applications cannot be installed independently without running the full WinJS application.

The best way to run tests is IME - create a separate WinJS project in your solution to run your tests.

Christopher Bennage has a blog post that describes the basic setup here: http://dev.bennage.com/blog/2012/08/15/unit-testing-winjs/

And I have a few blog posts that are moving a little along the way:

http://lostechies.com/derickbailey/category/winjs/

http://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/

http://lostechies.com/derickbailey/2012/08/21/a-winjs-specrunner-automating-script-tag-insertion-for-unit-tests/

If you do not like the idea of โ€‹โ€‹launching a separate project for your tests, or if you want QUnit instead of Jasmine or Mocha, check out QUnit-Metro: http://qunitmetro.github.com/QUnitMetro/ - it starts in the project with your real application and provides context menu in design mode to run tests for the page on which you are located.

I am not a fan of QUnit or how QUnit-Metro works on a page. But you may find it suitable if you do not like a separate project.

Hope this helps.

+10
source

All Articles