Skip to content

Latest commit

 

History

History
158 lines (110 loc) · 3.89 KB

Core-Test-Module-Framework-Test-Class.asciidoc

File metadata and controls

158 lines (110 loc) · 3.89 KB

Test Class

Overview

In this document we’ll show you sample test classes and how should you set them up.

The following image gives a general overview of a test class "lifecycle".

image52 new

More information on the methods and annotations used in this image can be found in the following chapter.

Methods and annotations

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() {

	}
}

BasePage method: setUp

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();
}

BasePage method: tearDown

The tearDown methods executes after the test. It allows the clean up of the testing environment.

Annotations

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.

Sample Setup

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();
    }
}