测试用例的分组未按预期在testng.xml中工作

问题描述 投票:0回答:1

我有多个要在测试套件中运行的测试用例。并实施了分组。我的testng.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="test">
<groups>
<run>
<include name="admin"/>
<include name="grneraluser"/>
</run>
</groups>
<classes>
<class name="TestCases.testclass1" />
<class name="TestCases.testclass2" />
</classes>
</test>
</suite>

TestCases.testclass1 is as below ::

@BeforeSuite(alwaysrun="true")
public void setup(){
...
}

@BeforeClass(groups={"admin"})
public void driversetup(){
....
}

@Test(groups={"admin"},priority=0)
public void login(){
....
}

@Test(groups={"admin"},priority=1)
public void dashboard(){
....
}
@Test(groups={"admin"},priority=2)
public void login1(){
....
}

@Test(groups={"admin"},priority=3)
public void dashboard1(){
....
}
-------------

TestCases.testclass2 is as below ::

@BeforeClass(groups={"grneraluser"})
public void driversetup(){
....
}

@Test(groups={"grneraluser"},priority=1)
public void forcash(){
....
}

@Test(groups={"grneraluser"},priority=2)
public void transact(){
....
}

当测试套件通过testng.xml运行时,而不是运行属于单个组的所有测试方法。它们按优先级从多个类运行。

我希望执行顺序为

@beforesuite 
@beforeclass - (of TestCases.testclass1, group={"admin"} ) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=0) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=1) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=2) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=3) 
@beforeclass - (of TestCases.testclass1, group={"generaluser"} ) 
@Test - (of TestCases.testclass2 , groups={"admin"},priority=1) 
@Test - (of TestCases.testclass2 , groups={"admin"},priority=2)

但是,它运行为:

@beforesuite 
@beforeclass - (of TestCases.testclass1, group={"admin"} ) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=0) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=1) 
@beforeclass - (of TestCases.testclass1, group={"generaluser"})  
@Test - (of TestCases.testclass2 , groups={"generaluser"},priority=1)  
@Test - (of TestCases.testclass1 , groups={"admin"},priority=2)  
@Test - (of TestCases.testclass2 , groups={"generaluser"},priority=2) 
@Test - (of TestCases.testclass1 , groups={"admin"},priority=3)

请提示我是否有任何遗漏

selenium testng grouping
1个回答
0
投票

请按如下所示更新您的testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="test" group-by-instances="true">
<groups>
<run>
<include name="admin"/>
<include name="grneraluser"/>
</run>
</groups>
<classes>
<class name="TestCases.testclass1" />
<class name="TestCases.testclass2" />
</classes>
</test>
</suite>

这里我添加了group-by-instances属性,该属性用于按类对测试进行分组。

在执行期间,testNG考虑了所有测试方法的优先级,并且由于您的两个测试类具有优先级= 1的测试方法,因此依次触发这两个方法,然后再进行优先级= 2的测试。

© www.soinside.com 2019 - 2024. All rights reserved.