TestNG setup/teardown methods
In the previous Rock Bands test class example, we listed some of the annotations that tell TestNG whether a certain method should be run before or after certain points in time during the test run. These are the setup and teardown methods. They come before and after a suite, test, groups, class, and method.
As simple as it may seem, there are various rules and orders of precedence when using them. Let's look at some examples.
Setup methods
When you build the test class, there will be certain Java methods annotated with @Test
, which tells TestNG that the method is a test and should be run. Those tests will run in random order by default except, if you use a dependent method, a sequential naming scheme, or a priority
attribute. That will force the tests to run in a specific order.
For all the methods in a suite of tests, there will be common actions that need to be executed before each suite, test, groups, class, or methods, and instead of calling the same setup method...