Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce before/after test execution callbacks in the TestContext framework [SPR-4365] #9043

Closed
spring-issuemaster opened this issue Jan 21, 2008 · 7 comments

Comments

@spring-issuemaster
Copy link
Collaborator

commented Jan 21, 2008

Filip Neven opened SPR-4365 and commented

Objective

Consider providing additional callback hooks in the TestExecutionListener API for enabling more fine-grained integration with third-party testing frameworks (e.g., Unitils) and custom testing code.

Building Block for JUnit 5 Support

Adding these new callbacks will also enabled Spring to support the new BeforeTestExecutionCallback and AfterTestExecutionCallback APIs in JUnit 5's Jupiter extension model.

Deliverables

  1. Introduce before/after test execution callbacks in the TestExecutionListener API.
  2. Introduce before/after test execution callbacks in TestContextManager.
  3. Introduce before/after test execution support in the SpringJUnit4ClassRunner.
  4. Introduce before/after test execution support in the SpringExtension for JUnit 5.
  5. Introduce before/after test execution support in AbstractTestNGSpringContextTests.
  6. Document that before/after test execution callbacks cannot be supported with JUnit 4 Rules.
  7. Introduce appropriate integration tests for the SpringJUnit4ClassRunner, the SpringExtension, and AbstractTestNGSpringContextTests.

Comments from Original Poster

Unitils is an open source testing project, offering features such as integration with dbunit, test database maintenance and support for mock objects.
The core of Unitils works in a similar fashion as the spring testcontext framework, with a testlistener that provides callbacks during the execution of tests. It's also been implemented for Junit 3.8, Junit 4 and TestNG.

An adaptor could be written that translates spring's listener calls into unitils listener calls. Such an adaptor could be easily implemented as an org.springframework.test.context.TestExecutionListener. However, unitils' listener system currently offers more hooks than spring's. Therefore we'd like to see spring's framework extended to add callbacks directly before and directly after executing the test method (after executing the @Before and before executing the @After methods).


Affects: 2.5.1

Attachments:

Issue Links:

  • #18151 Introduce support for JUnit 5 in the TestContext framework ("is depended on by")
  • #11259 Introduce a TestExecutionListener for DbUnit
  • #8640 Please allow TestExecutionListeners to fail the test

Referenced from: commits 087efa6, 833dead, f7f37cd, 6efb166, 80018c6, fd00840, 3da5fbe, da89332, 5302566

3 votes, 4 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 21, 2008

Filip Neven commented

This patch provides the necessary extra callbacks and implements them for all supported test frameworks

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 23, 2008

Juergen Hoeller commented

Filip, I'm afraid this will have to wait for 3.0 M1 since 2.5.5 has too many open issues of higher priority, and the 2.5 branch is going into maintenance mode after 2.5.5...

I will make sure to address this request in the first 3.0 milestone, with first snapshots to be available in July.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 15, 2009

Grzegorz Borkowski commented

Why is it set to Spring 3.1? If this is all about simply adding additional callbacks, it should be easy to have it in 3.0. The integration of Unitils with Spring TestContext would be very helpful for many projects, and it shouldn't wait forever to be done.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 22, 2015

Juergen Hoeller commented

To be revisited in the course of our JUnit 5 work...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 26, 2016

Sam Brannen commented

Since Spring Framework 5.0 will be based on Java 8, we are now planning to add these new callbacks as default interface methods in order to support backward compatibility for existing TestExecutionListener implementations.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 9, 2016

Sam Brannen commented

Ongoing work on this issue can be seen in the following branch:

https://github.com/sbrannen/spring-framework/commits/SPR-4365

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 11, 2016

Sam Brannen commented

Resolved in GitHub commit f7f37cd:

Introduce before/after test execution callbacks in the TCF

This commit introduces 'before' and 'after' test execution callbacks in
the Spring TestContext Framework. Specifically, this set of commits
introduces the following.

  • beforeTestExecution() and afterTestExecution() callbacks in the
    TestExecutionListener API

  • beforeTestExecution() and afterTestExecution() callbacks in
    TestContextManager

  • RunBeforeTestExecutionCallbacks and RunAfterTestExecutionCallbacks
    JUnit 4 statements that are used by the SpringJUnit4ClassRunner

  • Documentation in the class-level Javadoc for SpringMethodRule stating
    that before/after test execution callbacks cannot be supported with
    JUnit 4 Rules

  • Support for JUnit Jupiter's BeforeTestExecutionCallback and
    AfterTestExecutionCallback extension APIs in the SpringExtension for
    JUnit 5

  • Support for before/after test execution callbacks in
    AbstractTestNGSpringContextTests for TestNG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.