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

3.1k views Asked by At

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?

1

There are 1 answers

2
m4ktub On BEST ANSWER

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.