Using @FixMethodOrder [wp_ad_camp_5] To execute tests in a order in JUnit 4, annotate the class with @FixedMethodOrder passing one of enum MethodSorters items as parameter. Either one of the following can be used are parameter to @FixMethodOrder. MethodSorters.NAME_ASCENDING: This sorts
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.
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.
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.