Use different Spring test context configuration for different test methods

后端 未结 2 1385
一整个雨季
一整个雨季 2021-02-08 01:07

We have a Spring based JUnit test class which is utilizing an inner test context configuration class

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguratio         


        
2条回答
  •  逝去的感伤
    2021-02-08 01:56

    I use these approaches when I'm have to solve this:

    • Manually build the context in a setup method instead of using annotations.
    • Move the common test code to a base class and extend it. That allows me to run the tests with different spring contexts.
    • A mix of the two above. The base class then contains methods to build spring contexts from fragments (which the extensions can override). That also allows me to override test cases which don't make sense or do extra pre/post work in some tests.

    Keep in mind that annotations only solve generic cases. You'll have to replicate some or all of their work when you leave the common ground.

提交回复
热议问题