Karma / QUnit单元测试外部站点

时间:2015-03-19 23:11:09

标签: unit-testing ember.js karma-runner qunit karma-qunit

我在一个端口上运行了一个Portal应用程序 - http://localhost:10039。我正在尝试对单个Ember.js应用程序进行单元测试,这些应用程序通过portlet加载到Portal应用程序中。

我希望能够做的是让那些QUnit测试针对整个应用程序运行,该应用程序在我提到的其他端口上运行。但是,Karma似乎不喜欢在运行应用程序的端口上运行测试套件。

例如:

test('Page loads in browser', function() {
  visit('/login').then(function() {
    ok(exists('#login-form'), 'Page loaded successfully');
  });
});

...在9876端口成功启动了Karma,但收益......

Page loaded successfully@ 42 ms
Expected: true
Result: false
Diff: true false 
Source: 
    at http://localhost:9876/absolute/Users/me/Sites/app/node_modules/qunitjs/qunit/qunit.js:1933:13
    at http://localhost:9876/base/tests/unit-tests.js:9:8
    at isolate (http://localhost:9876/base/bower_components/ember/ember.js:36720:15)
    at http://localhost:9876/base/bower_components/ember/ember.js:36703:16
    at tryCatch (http://localhost:9876/base/bower_components/ember/ember.js:45817:16)
    at invokeCallback (http://localhost:9876/base/bower_components/ember/ember.js:45829:17)

是否可以运行我的测试套件,比如http://localhost:9876,让它针对另一个网站/端口http://localhost:10039运行测试?

我最接近答案的是Karma proxies,尽管代理似乎没有效果。 Karma仍然针对相对于其自己的端口9876的链接运行其测试。

我想补充说,如果只能在其他地方进行,我会对其他测试框架开放 - Jasmine,Mocha等。

谢谢!

1 个答案:

答案 0 :(得分:0)

karma用于运行单元测试,因此代码将被加载到karma客户端(localhost:9876)并在那里执行测试用例。

如果您计划使用门户网站应用程序运行某些端到端测试,则可以查看硒等替代方案。事实上,上面的测试(测试成功加载页面)非常适合硒。