您如何在cypress中对您的测试场景(';it()';)进行分组

您如何在cypress中对您的测试场景(';it()';)进行分组,cypress,Cypress,最近,我能够实现在“跳过”列下的测试报告中包含的目标,但我注意到其他应该通过的测试并没有出现在测试报告中 我是这样编码的: describe('My simple test class',()=>{ let rr = true beforeEach(()=>{ if(rr == true){ expect(2).to.equal(2) rr = true } else { rr =

最近,我能够实现在“跳过”列下的测试报告中包含的目标,但我注意到其他应该通过的测试并没有出现在测试报告中

我是这样编码的:

describe('My simple test class',()=>{
   let rr = true
   beforeEach(()=>{
       if(rr == true){
           expect(2).to.equal(2)
           rr = true
       } else {
          rr = false
       }
   })

   it('child1'()=>{
      if(rr == true){
            expect(4).to.equal(4)
        } else {
            cy.end      
        }
      // - - - here i wanted to have some sort of nested or another 'it() depends but I don't know how
   })

   it('not related'()=>{
      expect(5).to.equal(5)
   }) 

})
    • 现在当我在之前的声明通过时。在报告中,它仅出现在“通过”列2中,并引用下面的2个测试用例“child1”和“not related”
如果我在beforeach中所做的断言为false或不相等,那么显然child1将被跳过,它将以“Tests”列2的形式出现在报告中,以1的形式出现,以1的形式失败,以1的形式跳过,并且不通过,这应该是1,这应该是指“notrelated”测试

我是cypress的新手,我不知道如何有效地分组,这样做不会影响整个测试

 it's like this way - -
 parenta - test scenario
   - child1a - test scenario
   - child2a - test scenario
   - child3a - test scenario
parentb - test scenario
   - child1b - test scenario
   - child2b - test scenario
   - child3b - test scenario

so if parenta is by assertion turned into false or bug then all of its child will be skip but if parentb and its child are passed then in reports all should appear as follows:

Tests | Passing | Failing | Pending | Skipped
  8   |    4    |    1    |         |   3

where:
Tests is the total test available parenta + childa + parentb + childb
Passing is the total passed test cases which is the parentb and its child
Failing is 1 which refer to parenta as a test scenario that fails or returned bug
Pending is obviously zero
Skipped is 3 which refers to the child of parenta

重新考虑您的测试策略可能会很有用。使用条件跳过对测试所有组件和测试用例并没有真正的帮助。您正在运行测试,因此运行它们不应该破坏任何东西,也不应该造成任何伤害

您应该测试积极和消极的用例,并且运行每个测试用例(
it
),完全独立于所有其他测试用例。因此,当测试A失败时,跳过测试B是没有意义的。当测试失败并留下一些奇怪的状态时,请在每次生命周期方法之后在
中清除它。您可以阅读有关生命周期方法的更多信息

为了组织测试,可以使用嵌套的
描述
块:


描述('MyComponent',()=>{
它('应该是一些基本测试'()=>{
//试验
});
描述('someComplexFunctionOfMyComponent',()=>{
它('当X'时应该像案例A一样,()=>{
//测试用例A当X
});
它('当Y'时,应为类B',()=>{
//测试用例B当Y
});
});
});

哦,很抱歉没有包括描述,但我可以向您保证它已经包含了。我在这里写的东西就在“描述”块中……是的,这正是我的意思。独立运行,但有些测试用例称为“父级上的子级”,当父级出现错误时,子级将不得不跳过。这就是为什么如果发生这种情况,那些不属于自己的应该独立运行。这对于使用dependsonmethod的TestNG注释来说是很容易的,这正是我试图在Cypress上模拟的,我已经更新了我的答案,以便更清楚地说明我所说的“嵌套描述块”是什么意思。还试图解释为什么在测试A失败时跳过一些测试B没有任何意义。你只是在做测试。是的,我完全明白你的意思。这正是selenium中的TestNG框架在cypress中应该很容易实现的,看起来您真的需要硬编码。首先,我尝试了一种方法,它实际上可以在报告中显示在跳过的测试列上,但当我这样做时,如group Descripte块,一个块故意跳过,那么报告似乎不正确,它不显示skip。我认为这是有问题的。非常感谢您的回复