.skip() 和 .only() 的使用

.skip() 和 .only() 的使用

说明
  • 在做自动化测试中,跳过执行 某些测试用例,或只运行某些指定的测试用例,这种情况是很常见的
  • Cypress中也提供了这种功能
如何跳过测试用例

通过describe.skip() 或者 context.skip() 来跳过不需要执行的测试套件

复制代码
describe('ship test',()=>{
    describe.skip('跳过该测试套件',()=>{
        it('测试1',()=>{
            cy.log('测试用例1被执行');
        })
    })
})

通过 it.skip() 来跳过不需要执行的测试用例

typescript 复制代码
it.skip('测试用例2',()=>{
        cy.log('测试用例2');
});
指定执行测试套件或测试用例

当存在 .only() 指定某个测试套件或测试用例时,只有这个测试套件或测试用例会被执行 ,其他未加 .only() 的测试套件或测试用例都不会执行

通过 describe.only() 或者 context.only()来指定需要执行的测试套件

测试代码
typescript 复制代码
describe('only suite',()=>{
    context('suite1',()=>{
        it('case1',()=>{
            cy.log('case1');
        })
        it('case2',()=>{
            cy.log('case2');
        })
    })

    context.only('suite2',()=>{
        it('case3',()=>{
            cy.log('case3');
        })
        it('case4',()=>{
            cy.log('case4');
        })
    })

    context('suite3',()=>{
        it('case5',()=>{
            cy.log('case5');
        })
        it('case6',()=>{
            cy.log('case6');
        })
    })
})

通过 it.only() 来指定需要执行的测试用例

typescript 复制代码
describe('only suite',()=>{
    it.only('only case1',()=>{
        cy.log('case1');
    })

    it.only('only case2',()=>{
        cy.log('case2');
    })

    it('case3',()=>{
        cy.log('case3');
    })
})
相关推荐
测试19981 天前
接口测试工具:Postman的高级用法
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
程序员小远1 天前
如何编写测试用例?
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
Bug 挖掘机2 天前
从0到1做出可复用的 iOS 自动化测试 Skill,附真机演示效果
自动化测试·测试开发·ios
测试19983 天前
Selenium自动化测试框架的搭建
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
Thanks_ks3 天前
从辅助编码到架构重塑:基于 LLM 的智能开发工作流落地实战
自动化测试·大模型·llm·研发效能·模型微调·rag·提示词工程