I am using Spring and Java 11. I used non-static fields in my @Service, but I got a critical error on Sonar Qube saying:
"Members of Spring components should be injected"
So I changed these fields to static.
Now in my unit tests, I test my service, which is declared in this way:
@InjectMocks
@Spy
private myService myService;
But if I change a static field in one test, the value is reflected in the other test. How can I set all private static fields on values which are initialized on start:
private static Integer count = 1;
private static boolean isChecked = true;
Edit: I can add to my class I have also filed it with annotation @Autowired
@Autowired
private MySecondService mySecondService;
in test class, I have this object with annotation @Mock
@Mock
private MySecondService mySecondService;
So if a solution will be to use @Before or something like this and initialize this object in this method. I also need to initialize all Mock objects.