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

API for intercepting execution #1145

Closed
hwellmann opened this issue Nov 5, 2017 · 8 comments
Closed

API for intercepting execution #1145

hwellmann opened this issue Nov 5, 2017 · 8 comments

Comments

@hwellmann
Copy link

Overview

  • (X) Feature request.

With the present BeforeAll, BeforeEach, AfterEach, AfterAll extensions, it is possible to decorate test execution, but it is not possible to fully intercept it.

This is required for test frameworks like Pax Exam or Arquillian which currently use JUnit 4 runners as a test driver to first start a test container (e.g. a Java EE server or an OSGi framework) and then delegate test execution to an agent running within the container.

At the moment, the only way I see to implement equivalent functionality with JUnit 5 would be a custom test engine, which would require a lot of code duplication from junit-jupiter-engine since most potential hooks for overriding are package private or final.

In particular, I would like to override HierarchicalTestEngine.execute() or Node.before(), Node.execute(), Node.after().

A JUnit extension should be able to determine whether is is running under the (outer) test driver or in the (inner) test container. When running in the container, execution should proceed as normal. When running under the driver, execution should be delegated to the container via a suitable communication channel (e.g. a servlet request) provided by the extension.

@marcphilipp
Copy link
Member

Related issues: #20 and #157.

@hwellmann Thanks for raising this issue! Would you only want to intercept the execution of the test method or of other test class method and extensions as well?

@hwellmann
Copy link
Author

Other test class methods (like those annotated with @BeforeEach etc.) and other extensions (replacing JUnit 4 rules) will also have to be intercepted, since there is no point in executing them on the driver side, they only make sense within the test container.

Rather than intercepting individual methods, it might be more convenient to intercept the execution of an entire node (including all children and extensions).

@marcphilipp
Copy link
Member

Do the test driver and test container run in the same JVM?

@hwellmann
Copy link
Author

Not necessarily, containers may be local or remote.

@marcphilipp
Copy link
Member

How does the test driver communicate to the container what should be executed, especially when they run in different JVMs?

@hwellmann
Copy link
Author

That's the job of the extension, that's nothing I'd expect from JUnit.

For Java EE, we use a servlet to tunnel test requests and listener events over HTTP. For OSGi, we open a server socket. For JUnit 4, it was enough for the request to include a class name, method name and optionally a position index for parameterized tests to identify the test(s) to be executed.

@sbrannen
Copy link
Member

@hwellmann, does the InvocationInterceptor extension API introduced in #1852 meet your needs?

@marcphilipp
Copy link
Member

Closing due to lack of activity. Please reopen if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants