Jasmine有iit()
和ddescribe
,摩卡有it.only
和describe.only
,但我看不到任何讓QUnit專注於運行單個測試的方法。是否可以在Karma中使用QUnit來運行單個測試?
QUnit UI允許您運行單個測試,但是我無法看到如何在Karma內部使用它,因爲它不顯示QUnit UI。
Jasmine有iit()
和ddescribe
,摩卡有it.only
和describe.only
,但我看不到任何讓QUnit專注於運行單個測試的方法。是否可以在Karma中使用QUnit來運行單個測試?
QUnit UI允許您運行單個測試,但是我無法看到如何在Karma內部使用它,因爲它不顯示QUnit UI。
QUnit沒有很好的設計,但你可以改善它!
QUnit的過濾機制是validTest
函數,其讀取QUnit.config.filter
(字符串,測試名稱)。見https://github.com/jquery/qunit/blob/master/src/core.js#L820
有兩個問題:
validTest
做什麼),建議改變QUnit到,首先收集所有測試)
然後,實施包容性測試將會很簡單;-)
這是我的解決方案。它適用於我,但YMMV。
從 here
下載qunit - 卡瑪setup.js,qunit - 卡瑪launch.js然後,在你Gruntfile:
config.set({
frameworks: ['qunit'],
files: [
'your-app-files-here/**/*.js',
'qunit-karma-setup.js',
'your-tests-here/**/*.js',
'qunit-karma-launch.js'
]
});
現在,你可以使用omodule(),otest( ),oasyncTest()函數分別只運行選定的模塊或測試。
添加這對您的測試文件
var ttest = test;
test = function() {}
的頂部,並重新命名要運行到ttest
測試。看起來笨拙,但很簡單,效果很好。
我相信你可以使用only
。從文檔摘自:
test('my test 1', function (assert) { ... });
only('my test that will be run exclusively now', function (assert) { ... });
因此,不是用字test
的,你用only
。
^這工作真的很好 - 謝謝:) – shane