テストのスキップ/無効化
概要
テストモジュールの実行を回避するには、そのモジュールの `disabled` 属性を `true` に設定します。
tests/sampleTest.js
module.exports = {
'@disabled': true, // This will prevent the test module from running.
'sample test': function (browser) {
// test code
}
};
これは、失敗することがわかっている特定のテストを実行したくない場合に役立ちます。
個々のテストケースのスキップ
BDD Describes インターフェースを使用する場合のみ、個々のテストケースの無効化/スキップがサポートされます。テストケースをスキップするには、`test.skip()`、`it.skip()`、`xtest()`、または `xit()` のいずれかを使用して、そのようにマークします。これらはすべて同等です。
例
tests/sampleTest.js
describe('homepage test with describe', function() {
// skipped testcase: equivalent to: test.skip(), it.skip(), and xit()
it.skip('async testcase', async browser => {
const result = await browser.getText('#navigation');
console.log('result', result.value)
});
});
デフォルトインターフェースを使用している場合、簡単な回避策で比較的簡単に実現できます。テストメソッドを文字列に変換するだけで、Nightwatch はそれを無視します。
例を以下に示します。
tests/sampleTest.js
module.exports = {
'sample test': function (browser) {
// test code
},
// disabled
'other sample test': ''+function (browser) {
// test code
}
};
特定のテストケースのみの実行
テストスイート全体(つまり、`describe()` ブロック内の `it()` または `test()` 関数)内の特定のテストケースを実行する場合は、`it.only()` または `test.only()` 関数を使用します。これらは同等です。
例
以下は、`startHomepage` テストケースのみを実行し、残りを無視します。
tests/sampleTest.js
describe('homepage test with describe', function() {
test.only('startHomepage', () => {
// ...
});
test('other testcase', () => {
// ...
});
});