Announcement Announcement Module
Collapse
No announcement yet.
Problem specifying a test execution listener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem specifying a test execution listener

    I'm trying to specify a custom test execution listener, and my code looks something like this:

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"/applicationContext.xml"})
    @TestExecutionListeners(MyListener.class)
    public class RandomTest
    {
        @Autowired
        ApplicationContext ctx;
    However, it appears that the TestExecutionListeners annotation removes all of the default annotations. Thus, by specifying one listener of my own I loose the DependencyInjectionTestExecutionListener that is normally provided. (Therefore, the variable "ctx" is always null.)

    My questions are:
    • Is there a way to add a test execution listener without loosing the ones that are normally provided?
    • Are there any "gotchas" when dealing with the DirtiesContext or Transactional annotations while specifying a custom test execution listener?

    Thanks!

  • #2
    Extend one of the spring classes this explicitly registers the listeners again or add them yourself. It is assumed that when you specify the TestExecutionListener yourself that you want to be in full control (this is basically the framework default) and as such it doesn't register the defaults.

    Comment


    • #3
      This makes sense. When you say "Extend one of the spring classes...", which classes are you referring to?

      Comment


      • #4
        The spring test classes as documented in the reference guide, for instance AbstractTransactionalJUnit4SpringContextTests.

        Comment


        • #5
          Ah! I'd forgotten that there were test base classes. Cool. Thanks for your help!

          Comment

          Working...
          X