-
Notifications
You must be signed in to change notification settings - Fork 11
JUnit
Neodymium extends a JUnit4 test runner to implement the NeodymiumRunner
. The NeodymiumRunner
is used to provide our features like test data handling, multi browser support and the consequential test multiplication. On this site we give some insights on how this works when using Neodymium.
The NeodymiumRunner
can be used easily by annotating the test case class. Please see example below:
@RunWith(NeodymiumRunner.class)
public class DemoTest
{
@Test
public void ensureFunctionality()
{
// add test code
}
}
With Neodymium a test case can be executed with different test data sets and thus Data Driven Testing is possible. Furthermore, Neodymium offers support to run the test cases along to the data sets in different browsers. This is what we call the Neodymium multi browser support. This features can be combined with each other. While the multi browser support is activated by annotating classes or methods is the data set usage already active when a matching data file exists. Please follow the links below for more details on the topics.
@Browser
@SuppressBrowser
Please check the Multi browser support page for detailed information.
@DataSet
@SuppressDataSet
@DataFile
Please check the Test data provider page for detailed information.
In general the test execution order of JUnit > 4.11 applies. More info here. This means by default there is no fixed order within the methods annotated with @Test
.
The test methods are retrieved as unordered list but while computing the test multiplication for test data sets and browsers they are added as complete sets (cross product of method, browsers and test data sets) for each method that is effected by Neodymium's annotations (see above). JUnit's method ordering is applied first. The order of the used browsers is the same as stated within the test. The data sets are executed in the order they are listed within the data file or as specified by using the @DataSet
annotation. The browsers are applied before the data sets.
As stated above, JUnit does not execute the computed test methods in any particular order. For cases where a fix and predictable execution order is desired/required, JUnit's FixMethodOrder
annotation can be used for Neodymium tests as well (see example below).
###Example Given the following test class and let's assume we execute it with a data file containing 3 data sets:
@RunWith(NeodymiumRunner.class)
@Browser("Chrome_1024x768")
@Browser("Firefox_1024x768")
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OrderDemoTest
{
@Test
public void testC()
{
System.out.println("testC with browser: '" + Neodymium.getBrowserProfileName() + "' and data set: '" + Neodymium.dataValue("testId") + "'.");
}
@Test
// this overwrites the order of the data file
@DataSet(id = "dataSet3")
@DataSet(id = "dataSet2")
@DataSet(id = "dataSet1")
public void testB()
{
System.out.println("testB with browser: '" + Neodymium.getBrowserProfileName() + "' and data set: '" + Neodymium.dataValue("testId") + "'.");
}
@Test
// this overwrites the order of the test class
@Browser("Firefox_1024x768")
@Browser("Chrome_1024x768")
public void testA()
{
System.out.println("testA with browser: '" + Neodymium.getBrowserProfileName() + "' and data set: '" + Neodymium.dataValue("testId") + "'.");
}
}
The console output of the code above would then look like this:
testA with browser: 'Firefox_1024x768' and data set: 'dataSet1'.
testA with browser: 'Firefox_1024x768' and data set: 'dataSet2'.
testA with browser: 'Firefox_1024x768' and data set: 'dataSet3'.
testA with browser: 'Chrome_1024x768' and data set: 'dataSet1'.
testA with browser: 'Chrome_1024x768' and data set: 'dataSet2'.
testA with browser: 'Chrome_1024x768' and data set: 'dataSet3'.
testB with browser: 'Chrome_1024x768' and data set: 'dataSet3'.
testB with browser: 'Chrome_1024x768' and data set: 'dataSet2'.
testB with browser: 'Chrome_1024x768' and data set: 'dataSet1'.
testB with browser: 'Firefox_1024x768' and data set: 'dataSet3'.
testB with browser: 'Firefox_1024x768' and data set: 'dataSet2'.
testB with browser: 'Firefox_1024x768' and data set: 'dataSet1'.
testC with browser: 'Chrome_1024x768' and data set: 'dataSet1'.
testC with browser: 'Chrome_1024x768' and data set: 'dataSet2'.
testC with browser: 'Chrome_1024x768' and data set: 'dataSet3'.
testC with browser: 'Firefox_1024x768' and data set: 'dataSet1'.
testC with browser: 'Firefox_1024x768' and data set: 'dataSet2'.
testC with browser: 'Firefox_1024x768' and data set: 'dataSet3'.
Neodymium and its example projects use Maven as execution environment. For test executions we use the Apache Maven Surefire plugin.
By default there is also no particular order for the execution of the test case classes. But you can specify the order by adding the runOrder
parameter to the Surefire configuration within the pom.xml
file. Please check the official documentation for more details.
Overview
Neodymium features
- Neodymium configuration properties
- Neodymium context
- Utility classes
- Test data provider
- Test Environments
- Multi browser support
- Applitools Plugin
- Localization
- Highlight and Wait
- Advanced Screenshots
- Seperate Browser Sessions for Setup and Cleanup
Best practices and used frameworks
Special