testng - 我可以在一个 TestNG 案例中多次使用 @BeforeClass 吗?
问题描述
public class TestBase{
@BeforeClass
protected void setUp() throws Exception {}
@BeforeClass
protected void setUp2() throws Exception {}
@Test
public void queryAcquirerInfoById(){
}
}
如果我在一个 TestNG 类中使用两次“@BeforeClass”,这两种方法的顺序是什么?我可以指定这两种方法的顺序吗?</p>
解决方案
是的,您可以在一个类中添加多个 @BeforeClass 方法。它们将根据方法名称按字母顺序运行,例如在以下示例中,执行顺序为,
- 设置1()
- 设置2()
- queryAcquirerInfoById()
public class TestBase{
@BeforeClass
protected void setUp2() throws Exception {}
@BeforeClass
protected void setUp1() throws Exception {}
@Test
public void queryAcquirerInfoById(){
}
}
但是,您可以使用 'dependsOnMethods' 选项优先执行 @BeforeClass 方法,就像您编写
public class TestBase{
@BeforeClass (dependsOnMethods = { "setUp1" })
protected void setUp2() throws Exception {}
@BeforeClass
protected void setUp1() throws Exception {}
@Test
public void queryAcquirerInfoById(){
}
}
然后 setUp1() 将在 setUp2() 之前运行
推荐阅读
- sql - Oracle - 分析功能上的过滤器使查询变慢
- django - Django Datefield、TimeField 和 DecimalField 不显示
- python - 没有得到正确的 URL Beautifulsoup python
- r - 在 R 的堆叠 ggplot2 条形图中使 Y 轴总计?
- relational-database - theta join和inner join有什么区别?
- erlang - 如何在 Elixir/mix 项目中加载 Erlang 模块?
- json - 无法解析 JSON 数据以与 rxjs 交互
- android - 警告:忽略匿名内部类的 InnerClasses 属性
- google-cloud-platform - 使用 FDW 扩展从本地数据库到 Cloud SQL 是否可能或可行?
- android - 如何将训练有素的 scikit-learn 模型导入 android 项目