emberjs使用的测试工具为qunit.js:
加载:将runner.js添加到Index.html;大致内容:
if (window.location.search.indexOf("?test") !== -1) { document.write( ‘<div id="qunit"></div>' + '<div id="qunit-fixture"></div>' + '<div id="ember-testing-container">' + ' <div id="ember-testing"></div>' + '</div>' + '<link rel="stylesheet" href="/assets/tests/runner.css">' + '<link rel="stylesheet" href="/assets/tests/vendor/qunit-1.15.0.css">' + '<script src="/assets/tests/vendor/qunit-1.15.0.js"></script>' + '<script src="/assets/tests/tests.js"></script>' ) }
其中ember-testing是显示原本页面的部分,通过runner.css来设置;在原本页面中将在url最后添加"?test"跳转到测试页面;
test.js的基本结构:
App.rootElement = '#ember-testing'; App.setupForTesting(); App.injectTestHelpers(); function exists(selector) { return !!find(selector).length; }
integration-testing 可参考: web web
基本结构:
module("Integration tests", { setup: function() { // before each test, ensure the application is ready to run. Ember.run(App, App.advanceReadiness); }, teardown: function() { // reset the application state between each test App.reset(); } }); test("Check Graph and links in index page", function() { visit("/"); andThen(function() { ok(exists("*"), "Found HTML!"); }); });