Cypress で特定のテストだけ実行する方法
Node.js のテスティングライブラリ Cypress で特定のテストだけを実行する方法についてです。
確認時のバージョン
- Node.js
v17.3.1 - Cypress
9.2.1
ファイル単位で絞り込む方法とファイル内のケース単位で絞り込む方法の 2 つの方法があります。
ファイルで絞り込む
cypress run の --spec オプションを使用します。
特定のファイル:
cypress run --spec "cypress/integration/header/menu.spec.js"特定のディレクトリ以下:
cypress run --spec "cypress/integration/header/**"複数のファイル:
cypress run --spec "cypress/integration/header/menu.spec.js,cypress/integration/footer/menu.spec.js"参考:
ファイル内のケースで絞り込む
テストケースを記述するための it() を it.only() や it.skip() に書き換えることで、そのケースが含まれるテストグループにおいて実行するケースを制限することができます。
it.only():
describe('Unit Test for ...', () => {
// このケースだけを実行する
it.only('...', () => {
// ...
})
it('...', () => {
// ...
})
it('...', () => {
// ...
})
})it.skip():
describe('Unit Test for ...', () => {
// このケースは実行しない
it.skip('...', () => {
// ...
})
it('...', () => {
// ...
})
it('...', () => {
// ...
})
})参考:
Cypress の実ブラウザを使ったテストは比較的時間がかかるので、必要な部分だけを実行できると効率的です。