【发布时间】:2013-12-05 08:17:21
【问题描述】:
为什么JUnit 中的@BeforeClass 方法是static 而TestNG 中的non-static? TestNG 是对JUnit 的改进,那么他们为什么选择这种实现方式呢?
因为@BeforeClass 只运行一次,所以设置static 比设置为非静态更有意义。同样在 TestNG 中,在哪个实例上调用了 @BeforeClass 方法?有人可以举个例子更好地理解吗?
【问题讨论】:
-
请注意,TestNG 的注解是在 JUnit 之前开发的; TestNG 是对 JUnit
v3.*的改进,但现在它们看起来大致相同,因为 JUnit 也有注释(在 JUnitv4.*)。