2013-09-24 44 views

回答

2

QUnit沒有很好的設計,但你可以改善它!

QUnit的過濾機制是validTest函數,其讀取QUnit.config.filter(字符串,測試名稱)。見https://github.com/jquery/qunit/blob/master/src/core.js#L820

有兩個問題:

  1. 只允許選擇一個測試,
  2. 你需要事先知道所選擇的測試名稱(因爲測試被創建時過濾)。使用自定義的「過濾器」功能執行(指當

    • 過濾器(默認的實現可以做到當前validTest做什麼),
    • 過濾器測試:

建議改變QUnit到,首先收集所有測試)

然後,實施包容性測試將會很簡單;-)

3

這是我的解決方案。它適用於我,但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()函數分別只運行選定的模塊或測試。

+0

^這工作真的很好 - 謝謝:) – shane

1

添加這對您的測試文件

var ttest = test; 
test = function() {} 

的頂部,並重新命名要運行到ttest測試。看起來笨拙,但很簡單,效果很好。

0

我相信你可以使用only。從文檔摘自:

test('my test 1', function (assert) { ... }); 

only('my test that will be run exclusively now', function (assert) { ... }); 

因此,不是用字test的,你用only

相關問題