问题使用TestNG的@BeforeTest注释 [英] Issue in using @BeforeTest annotation in testng
问题描述
我写的自动化code为我的移动网站。
I am writing automation code for my mobile site.
1级: -
public class Sample{
@BeforeTest
public void createUser(){
// code to create user
}
@Test
public void verifyUser(){
// code to verify user
}
@AfterTest
public void deleteUser(){
// code to delete user
}
}
如同 1级
。我有不同的类别,如类2
,在Class3
, CLASS4
Like Class1
. I have different classes such as Class2
, Class3
, Class4
.
testing.xml
testing.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1">
<test name="Regression1" parallel="false" preserve-order="true">
<classes>
<class name="Class1"/>
<class name="Class2"/>
<class name="Class3"/>
<class name="Class4"/>
</classes>
</test>
</suite>
命令来运行: -
Command to run:-
mvn -Dtests=testing.xml test
当我运行上面的命令, @BeforeTest
从 1级
,类2
,在Class3
, CLASS4
首先调用。这意味着4个用户正在运行的所有测试前先创建。那么只有 1级
测试类2
等运行,那么。 Atlast @AfterTest
所有班级正在运行(删除所有的用户atlast)。
when i run above command, @BeforeTest
from Class1
, Class2
, Class3
, Class4
are called first. It means 4 users are created firstly before running any test. Then only Class1
Test is running then Class2
and so on. Atlast @AfterTest
from all classes are running(deleting all user atlast).
我不希望这种情况。
我需要以下方式来运行我的每个测试: -
I need the following way to run my each test:-
- 创建的用户
- 验证用户
- 删除用户
我需要我的 1级
执行第一个完全那么类2
等。
I need my Class1
executed first fully then Class2
and so on.
是否有TestNG的注释中的任何变化,我必须做什么?
Is there any change in annotation for testng i have to do?
推荐答案
使用 BeforeMethod
而不是 BeforeTest
的。在 BeforeTest
方法之前运行你的&lt;试验&GT;
在标记的testng.xml
和您的 @Test
方法之前不会。
,还可以使用 AfterMethod
而不是 AfterTest
课程。
Use BeforeMethod
instead of BeforeTest
. The BeforeTest
method will run before your <test>
tag in testng.xml
and not before your @Test
method.
And also use AfterMethod
instead of AfterTest
of course.
检查我的答案另一个类似的问题:<一href=\"http://stackoverflow.com/questions/30587454/difference-between-beforeclass-and-beforetest-in-testng/30591902#30591902\">Difference BeforeClass和BeforeTest TestNG中之间
Check my answer for another similar question: Difference between BeforeClass and BeforeTest in TestNG
这篇关于问题使用TestNG的@BeforeTest注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!