0

I try to run test for spring framework. I use only the xml context. In test (JUnit) class I specify

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"springContext.xml"})
public class MyTest extends TestCase {
    @Test
    public void test() {

    }
}

but I don't know how to get access to the spring context in the @Test method? I don't can use of @Autowired annotation, because I don't use annotation driven context

jonua
  • 1,915
  • 3
  • 17
  • 27

1 Answers1

2

The test class is like a regular bean. So far you can use both of those in your test class:

  • autowire ApplicationContext
  • implement ContextAware interface

See How to inject ApplicationContext itself

Community
  • 1
  • 1
Martin Strejc
  • 4,307
  • 2
  • 23
  • 38