Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize test class before context initialization while Spring testing?

I have my beans reading and writing some data on disk while working and configuring and would like to work with these files during tests.

For example, I would like to prepare some files on disk before context configuration and after of it configuration but before tests.

How to use run some code at these moments?

like image 660
Suzan Cioc Avatar asked Dec 11 '25 19:12

Suzan Cioc


1 Answers

If you are using @RunWith(SpringJUnit4ClassRunner.class) then you could provide a different class, based on Spring's, and override methods to execute what you want before the context is initialized. But normally you can do the setup and tear down in the test itself by using @BeforeClass and @AfterClass.

like image 94
m4ktub Avatar answered Dec 13 '25 07:12

m4ktub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!