.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');
    })
})
相关推荐
念越4 小时前
自动化测试入门指南:Selenium环境搭建+第一个实战案例
自动化测试·selenium·测试工具·蓝桥杯
深念Y1 天前
Chrome MCP Server 配置失败全记录:一场历时数小时的“fetch failed”排查之旅
前端·自动化测试·chrome·http·ai·agent·mcp
程序员小远1 天前
单元测试知识详解
自动化测试·软件测试·python·测试工具·职场和发展·单元测试·测试用例
纳米软件2 天前
电源模块纹波测试自动化方案设计与实践
自动化测试·自动化·labview·电源测试系统·atecloud
程序员小远3 天前
软件测试之功能测试详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
程序员杰哥4 天前
Jmeter正则表达式提取器和JSON提取器基础用法
自动化测试·软件测试·测试工具·jmeter·正则表达式·json·测试用例