The actual tests that will be executed are located in the so-called Test Classes. Starting a new project, a new package should be created.
Source folder: mrchecker-app-under-test/src/test/java
Name: com.example.selenium.tests.tests.YOUR_PROJECT
Test classes have to extend the BaseTest
class.
public class DemoTest extends BaseTest {
@Override
public void setUp() {
}
@Override
public void tearDown() {
}
}
This method will be executed before the test. It allows objects to be instantiated, e.g. Page objects.
@Override public void setUp() { someTestPage = new SomeTestPage(); }
The tearDown methods executes after the test. It allows the clean up of the testing environment.
The @Test
annotation indicates that the following method is a test method.
The @ParameterizedTest
annotation indicates that the following method is a test method. Such methods are inherited unless they are overridden.
The @Tag
is used to declare tags for filtering tests.
The @DisplayName
declares a custom name for a test or a method (not inherited).
The @BeforeAll
denotes that the annotated method should be executed before all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class.
The @AfterAll
denotes that the annotated method should be executed after all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class.
The @BeforeEach
denotes that the annotated method should be executed before each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class.
The @AfterEach
denotes that the annotated method should be executed after each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class.
Initialize a new test method by using the @Test
annotation.
@Test public void willResultBeShown() { }
This method will interact with a page object in order to test it.
public class SampleTest extends BaseTest {
@Override
public void setUp() {
BFLogger.logInfo("Open home page before each test");
}
@Override
public void tearDown() {
BFLogger.logInfo("Clean all data updated while executing each test");
}
@BeforeAll
public static void setUpClass() {
SAMPLE_OBSERVER.addObserver(testObserver);
}
@BeforeEach
public void setUp() {
throw new RuntimeException();
}
@Test
public void test1() {
BFLogger.logInfo("[Step2] Filter by \"Creation Date\" - Descending");
BFLogger.logInfo("[Step3] Set $1 for first 10 Users in column \"Invoice to pay\"");
}
@AfterEach
public void teardown() {
throw new RuntimeException();
}
@BeforeEach
public void setUp() {
throw new RuntimeException();
}
@Test
public void test2() {
BFLogger.logInfo("[Step2] Filter by \"Invoice to pay\" - Ascending");
BFLogger.logInfo("[Step3] Set $100 for first 10 Users in column \"Invoice to pay\"");
}
@AfterEach
public void teardown() {
throw new RuntimeException();
}
@AfterAll
public static void teardown() {
throw new RuntimeException();
}
}