views:

147

answers:

1

By experiment, I find that SpringJunit4ClassRunner treats the context and its beans as 'class scope' in the JUnit sense of scope. It inititializes my beans once for the entire set of tests in the class.

Is there any way to use this mechanism and get these things to be 'test scope'? In short, I wish that the context was being loaded as @Before instead of @BeforeClass.

+4  A: 

You can annotate test methods that dirty the Spring context with @DirtiesContext, (documented here) causing the context to be re-loaded for subsequent tests in the class.

I realise that this isn't quite what you're asking for, but perhaps it will do what you need.

Tom