Unit Test your Test Automation Framework with Mockito

By: Slav Kurochkin

When testing financial application you most likely going to interact with dates, some rules would happen after another, or when deadline has passed, I bet you would perform some calculation based on a given information and set appropriate values.

By saying all of those things I assume you already abstracted most of your methods, which is performing all dirty work for your UI Automation Framework. Then I would call your Test Automation Framework an application which require unit tests of your methods, mocking objects and data, that is where Mockito is appearing on a scene, it is Java based testing framework which allow you to mock objects and provide you an options to return values you need in order to complete your unit tests on a green line.

In order to start using Mockito add dependency to your pom.xml file, or simply add jar file to the framework.

<dependency>
	<groupId>org.mockito</groupId>
	<artifactId>mockito-all</artifactId>
	<version>1.9.5</version>
</dependency>

The thing I like about Mockito, it is consistent with BDD approach I'm trying to use in our Test Automation Framework, for example you can find a good use of when/then conditions.

And of cause you wouldn't have problems to integrate your tests with existing test runners, in our case we use JUnit.

 @Mock
    private DatesHelper mock;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    private static String month = "01";
    private static String day = "01";
    private static String year = "2015";
    private static String date = "01/04/2015";

    @Test
    public void threeDaysAfterCalendarTest() {
        assertEquals("01/04/2015", mock.getThreeDaysAfterCalendar(month, day, year));
    }
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.