E
E
Eugenue Cesarevich2020-12-29 23:00:30
Java
Eugenue Cesarevich, 2020-12-29 23:00:30

How to change time for JUnit 5 test?

I'm testing a service using JUnit 5. In the service, before performing the action, LocalTime.now() is called and it is checked that the time is now less than 11:00. For tests, I somehow need to make LocalTime.now() in the service return the time before 11:00, regardless of the real time. How can this be checked?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BorLaze, 2020-12-29
@BorLaze

Maybe something will help from here: https://www.baeldung.com/java-override-system-time

I
illuzor, 2020-12-30
@iLLuzor

Mockito can mock static methods:
https://asolntsev.github.io/en/2020/07/11/mockito-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question