0
votes

I wrote two test(I mean different classes) that is configured with this annotations:

@RunWith(SpringRunner.class)
@SpringBootTest

When I run them solitary - everything is Ok Magic happens when I run them simultaneously using 'test' task from gradle. One test creates an instance and then, somehow, transfer it to another class. Has anyone ever met smth like this?

1
If you are talking about the ApplicationContext (what you call "instance"): this is the default behaviour with Spring Test: ApplicationContext is reused between tests. see more details in this answer : stackoverflow.com/a/44181188/6899896 - M.Ricciuti
@M.Ricciuti, thanks. Didn't know about this. - user7739454

1 Answers

0
votes

You could use @DirtiesContext to tell that a test class will be modifying the ApplicationContext. Therefore any other subsequent test class will not pick up that modification

@DirtiesContext
@RunWith(SpringRunner.class)
@SpringBootTest