Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are advantages of using @ContextHierarchy over pure @ContextConfiguration

Hi I don't understand what advantages give me usage of @ContextHierarchy like below:

@ContextHierarchy({
  @ContextConfiguration("/test-db-setup-context.xml"),
  @ContextConfiguration("FirstTest-context.xml")
})
@RunWith(SpringJUnit4ClassRunner.class)
public class FirstTest {
 ...
}

@ContextHierarchy({
  @ContextConfiguration("/test-db-setup-context.xml"),
  @ContextConfiguration("SecondTest-context.xml")
})
@RunWith(SpringJUnit4ClassRunner.class)
public class SecondTest {
 ...
}

over usage of single @ContextConfiguration with locations argument, like below:

@ContextConfiguration(locations = {"classpath:test-db-setup-context.xml", "FirstTest-context.xml", "SecondTest-context.xml" })

In each case, application contexts are shared across diffrent junit test classes.

like image 970
QuestionMaker Avatar asked Apr 29 '17 11:04

QuestionMaker


People also ask

What is the use of @ContextConfiguration annotation?

Annotation Type ContextConfiguration. @ContextConfiguration defines class-level metadata that is used to determine how to load and configure an ApplicationContext for integration tests.

What is context hierarchy?

@ContextHierarchy is a class-level annotation that is used to define a hierarchy of ApplicationContexts for integration tests.


1 Answers

The difference is that beans in each context within the context hierarchy can't see beans in the other the context. So you can isolate different parts of your item under test.

like image 166
Guy Avatar answered Nov 15 '22 22:11

Guy