I have a base base class that I use as the basis for my unit tests (TestNG 5.10). In this class, I initialize the entire environment for my tests by setting up database mappings, etc. This abstract class has a method with @BeforeClass annotation that performs initialization.
Then I extend this class with specific classes in which I have @Test methods as well as @BeforeClass methods. These methods initialize the class-specific environment (for example, put some records in the database).
How can I enforce a certain order of annotated @BeforeClass methods? I need those from an abstract base class that must be executed before those propagated in the class.
Example:
abstract class A { @BeforeClass doInitialization() {...} } class B extends A { @BeforeClass doSpecificInitialization() {...} @Test doTests() {...} }
Expected Order:
A.doInitialization B.doSpecificInitialization B.doTests
Actual order:
B.doSpecificInitialization // <- crashes, as the base init is missing (A.doInitialization // <---not executed B.doTests) // <-/
java unit-testing testng
Dominik Sandjaja Jan 25 2018-10-25 14:02
source share