SupportWriter space ↗
REFERENCE LIBRARY

References from other publishers

Republished articles with source attribution. This collection is separate from Diary Coding’s original guides and does not display ads.

Read original guides → · Editorial policy

FOR YOUR CURIOSITY

Latest notes.

JUNIT / NOTES</>↗
JUnit13 Jul 2026

How do I use @Mock and @InjectMocks with JUnit?

To use @Mock and @InjectMocks with JUnit, you typically use them with Mockito. @Mock creates a fake/mock dependency. @InjectMocks creates the class under test and injects the mocks into it. With JUnit 5, you enable Mockito using @ExtendWith(MockitoExtension.class). 1. Add Mockito dependencies Maven <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.4</version> <scope>test</scope> </dependency> <dependency> <gr...

Wayan · 4 min read
JUNIT / NOTES</>↗
JUnit13 Jul 2026

How do I mock dependencies in unit tests?

To mock dependencies in unit tests, you usually use a mocking framework such as Mockito. Mocking lets you test one class in isolation without running the real logic of its collaborators. Basic Mockito Example Suppose you have a service that depends on another class: @Service public class MyService { private final MyDependency dependency; public MyService(MyDependency […]

Wayan · 3 min read
JUNIT / NOTES</>↗
JUnit13 Jul 2026

How do I use Mockito with JUnit?

To use Mockito with JUnit, you add Mockito to your test dependencies, enable Mockito in your JUnit test class, then create mocks and define their behavior. Below is a simple JUnit 5 + Mockito example. 1. Add Dependencies Maven <dependencies> <!– JUnit 5 –> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.4</version> <scope>test</scope> </dependency> <!– Mockito Core –> <dependency> […]

Wayan · 4 min read
JUNIT / NOTES</>↗
JUnit13 Jul 2026

How do I write tests for Java records?

Java records are compact classes designed to hold immutable data. Because records automatically provide a constructor, accessor methods, equals(), hashCode(), and toString(), testing them is usually simpler than testing ordinary classes. In most cases, you do not need to test Java’s generated record behavior directly. Instead, test: custom validation in the compact constructor custom methods […]

Wayan · 8 min read
JUNIT / NOTES</>↗
JUnit13 Jul 2026

How do I write tests for utility classes?

Utility classes are usually tested like any other unit: test their public behavior, especially calculations, transformations, validation rules, edge cases, and error handling. The main difference is that utility classes often have static methods, so your tests usually call the method directly instead of creating an object. 1. Test Useful Behavior, Not the Fact That […]

Wayan · 7 min read
JUNIT / NOTES</>↗
JUnit12 Jul 2026

How do I structure unit tests in a real Java project?

In a real Java project, unit tests should be organized so they are easy to find, run, understand, and maintain. A good structure follows the same shape as your production code and keeps tests focused on behavior. Most Java projects use this standard layout: project-root ├── src │ ├── main │ │ └── java │ […]

Wayan · 12 min read
✳

Knowledge grows when shared.

Stay curious. There is always something new to learn.

Explore notes ↗
Putu Adi Guna Permana
ABOUT THE AUTHOR

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.