Software Development

Three ways to mock an object using Mockito

If you’re new to Mockito and have only seen a sample or two on the Internet, you might find other examples create mock objects in different ways using the same framework. As a matter of fact, there are three (3) ways to create mock objects in Mockito.

Read More...

Software Development

Capture Argument To Method in Mockito

This post shows how to capture arguments our codes passed to a mock’s method. To do this, a method must accept reference types. Then, we use Mockito.verify() method. Then, pass

Read More...

Java, Software Development, Spring

Spring Boot – Loading Data Using a SQL Script

This post demonstrates how loading data from an SQL script for a particular database platform. This is ideal for development stage when you need some seed data to fill in existing database tables.

Read More...

MySQL, Software Development

Truncate MySQL Tables Before DBUnit Loads Data

This post is about truncating all tables in a MySQL database before DbUnit loads data via @DatabaseSetup. Doing it in @Before method does not work. DBUnit loads the data first via @DatabaseSetup before delegating calls to a @Before method.

Read More...

Software Development

Spring Boot – Access Spring ApplicationContext in JUnit Tests

This post shows how to access Spring ApplicationContext object in JUnit tests.

Read More...

Software Development

Easy Reflection using Spring ReflectionTestUtils

This post demonstrates how to get and set instance variables and invoke methods via the Reflection API using Spring ReflectionTestUtils. There are key reasons to do things via Reflection: 1) test non-public methods (not recommended, though), and 2) inaccessible instance variables (to mock).

Read More...

Software Development

Using Mockito @InjectMocks with Constructor and Field Injections

There is a scenario to watch out for where we have class with a few instance variables of reference types but not all of them get initialized via a constructor. This post demonstrates shows how we could unknowingly miss initializing other mocks in a class and how to fix them.

Read More...

Software Development

Reuse Unit Tests by Converting them to Parameterized Tests

This post demonstrates how to reuse our unit tests with JUnit Parameterized. Let’s say, we have a JUnit test class that tests for, for example, a single web browser’s “browse-to-URL” functionality in various scenarios and we want to reuse those tests for other browsers with the least code change.

Read More...

Software Development

JUnit 4 – Run Test Method More than Once

This post demonstrates how to perform repeated tests in JUnit 4 for this post. It involves creating a class that implements the TestRule interface, another class that implements Statement interface and a new annotation.

Read More...

Software Development

Group JUnit Test Cases using @Suite.SuiteClasses

Grouping Unit Tests [wp_ad_camp_5] At times there are certain set of unit tests we want to execute automatically. These tests may be critical or have been simply grouped for some

Read More...