Skip to content

Introduce mechanism for registering default TELs if a custom TEL is registered via @TestExecutionListeners [SPR-8854] #13496

@spring-projects-issues

Description

@spring-projects-issues

Saurabh Chandra opened SPR-8854 and commented

Status Quo

As of Spring Framework 3.2, the TestExecutionListener implementations ServletTestExecutionListener DependencyInjectionTestExecutionListener, DirtiesContextTestExecutionListener, and TransactionalTestExecutionListener are automatically registered by default.

However, if a custom TestExecutionListener is registered via @TestExecutionListeners then the defaults will not be registered. In most common testing scenarios, this effectively forces the user to manually declare all default listeners in addition to any custom listeners, for example:

@TestExecutionListeners(
  {
    MyCustomTestExecutionListener.class,
    ServletTestExecutionListener.class,
    DependencyInjectionTestExecutionListener.class,
    DirtiesContextTestExecutionListener.class,
    TransactionalTestExecutionListener.class
  }
)

The problem with this approach is that it requires that the user know exactly which listeners are registered by default. Moreover, this set can change from release to release -- for example, ServletTestExecutionListener was added in release 3.2.

Proposal

Provide a mechanism for instructing the TestContext framework to register all default TestExecutionListeners in addition to an explicitly configured custom TestExecutionListener.

This could be achieved via a new boolean flag in @TestExecutionListeners. Alternatively, an enum could be introduced that specifies how defaults should be handled -- for example, prepended to custom listeners, appended to customer listeners, or excluded (i.e., the current behavior).

If this proposal is not implemented, it should at least be clearly documented in both Javadoc and the reference manual that the defaults are not prepended by default when specifying a custom TestExecutionListener.


Affects: 3.0 GA

Issue Links:

Referenced from: commits 66250b1

2 votes, 2 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions