For optimizing purpose I need to customize TestExecutionListeners
invoking logic
In my case I have one ApplicationContext
and two types of tests:
- Ones which use
WebDriver
(let’s call itObservableTest
) - Ones which use
RestTemplate
andJdbcTemplate
(let’s call itApiTest
)
Each type uses its own TestExecutionListener
:
ObservableTest
-ObservableTestListener
ApiTest
-ApiTestListener
Both ObservableTestListener
and ApiTestListener
extend TestListener
where prepareTestInstance()
is defined
ObservableTestListener
implements beforeTestClass()
and afterTestClass()
methods as well as ApiTestListener
does
I need combine test types above in one JUnit TestSuite
in the next way:
- For each test
prepareTestInstance()
is invoked - As soon as first
ObservableTest
is about to be instantiated,beforeTestClass()
ofObservableTestListener
is executed - The same with
ApiTest
afterTestClass()
ofObservableTestListener
is invoked when lastObservableTest
is finished in current Suite- The same with
ApiTest
Things got even more complicated as each test may be run in one suite and in different ApplicationContexts
(due to different profiles usage)
I would be very grateful for any hint and digging direction to implement such logic properly
I have two ideas so far:
- Implementing custom
Runner
(I'm not confident it is even possible) - Notify
TestContextManager
somehow that particular method (beforeTestClass()
orafterTestClass()
) should or should not be invoked. I have a feeling thatcustom@BootstrapWith
SpringClassRule
should help me in that
Thanks!