When each test needs its own setup, annotate a method with JUnit Jupiter’s @BeforeEach. JUnit runs that method before each test, so it can create the objects the test will use. section 15.2
Listing 15.2 Creating the object whose method we want to unit test
public class TransferServiceUnitTests {
private AccountRepository accountRepository;
private TransferService transferService;
@BeforeEach #A
void setUp() {
accountRepository = mock(AccountRepository.class); #B
transferService = new TransferService(accountRepository); #C
}
}In this transfer-service test, setUp() creates a mock repository and passes it to the service before each test. section 15.2

