Results 1 to 5 of 5

Thread: Problem specifying a test execution listener

  1. #1
    Join Date
    Jun 2012
    Posts
    7

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jun 2012
    Posts
    7

    Default

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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    The spring test classes as documented in the reference guide, for instance AbstractTransactionalJUnit4SpringContextTests.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jun 2012
    Posts
    7

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •