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.
Spring Boot – Access Spring ApplicationContext in JUnit Tests
This post shows how to access the Spring ApplicationContext object in JUnit tests. Now, why would we want to do that? Well, sometimes, we need to work directly with the ApplicationContext object. Spring, Java, and Other Requirements We used the
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).
Truncate MySQL Tables Before DBUnit Loads Data
This post shows how to truncate a table in MySQL before DbUnit loads data via @DatabaseSetup. Truncating the tables in the @Before method does not work because DBUnit loads the data first via @DatabaseSetup before delegating calls to a @Before
Execute specific unit test in Maven using Eclipse
Okay, your project has hundreds of unit tests, but you only need to execute one or perhaps only all tests from a JUnit test file. Maven allows for that, and Eclipse makes it more convenient. Eclipse JUnit Run Configuration With
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.
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 reasons. To group JUnit test cases, we use @Suite.SuiteClasses annotation.
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.
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 an instance of ArgumentCaptor to the mock’s method. Capture Argument
Find out if an object is a mock or spy in Mockito
The need for it [wp_ad_camp_5] Finding out if an object is a mock or spy in Mockito may not (or never) be part of your usual automated unit tests but in some cases (advanced usage of JUnit/Mockito) you may need