简体   繁体   中英

What does @ContextConfiguration refer to?

I've just parachuted into a spring project and they don't believe in unit testing.

I am trying to set up my own unit testing environment.

May I know what does the annotation @ContextConfiguration refer to?

What about for @Repository, I can't seem to initialize it.

What does the file look like and where is it usually resided?

It defines class-level metadata that is used to determine how to load and configure an application context for integration tests.

Typically my spring unit test class look like this

@ContextConfiguration("/personservicetest-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class PersonServiceTest {
  ...
}

And a spring application context will be built based on personservicetest-context.xml file (relative to classpath root)

@ContextConfiguration is used to determine how to load and configure an ApplicationContext in integratrion tests, like in this JUnit test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/test5.xml")
public class Test5 {
    @Autowired
    ConnectionFactory f1;

    @Test
    public void test() throws Exception {
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM