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 adapters for JUnit 4 Rules #433

Closed
3 tasks done
sbrannen opened this issue Jul 25, 2016 · 6 comments
Closed
3 tasks done

Introduce adapters for JUnit 4 Rules #433

sbrannen opened this issue Jul 25, 2016 · 6 comments

Comments

@sbrannen
Copy link
Member

sbrannen commented Jul 25, 2016

Goals

Introduce adapters for common JUnit 4 Rules in the junit-jupiter-engine.

The dependency from junit-jupiter-engine to JUnit 4 must be an optional dependency.

This support should be automatically enabled if junit-4.x.jar is on the classpath.

Proposed Candidates

  • ExpectedException
  • ExternalResource
  • Verifier

Related Issues

Related Blog Posts

@sbrannen sbrannen added this to the 5.0 M3 milestone Jul 25, 2016
@kcooney
Copy link
Member

kcooney commented Jul 30, 2016

@sbrannen Is the proposal to allow these three Rules in JUnit Jupiter tests but not others?

@sbrannen
Copy link
Member Author

@kcooney, yes, that's correct.

The JUnit 5 team analyzed the existing rules in JUnit 4 and selected ones that can be supported with current extension APIs in JUnit Jupiter.

JUnit 4 rules not in the above list cannot currently be supported without some sort of Statement-like extension which is currently not planned for JUnit Jupiter.

@mlevison
Copy link

Suggestion (from vacation again, excuse top posting).

Adapters will promote the continued use of the old rules.

Consider as an alternative providing mappings. For bonus points, automate
the mapping via regex (of simple enough) or a full blown test rewriter (ie
Java code).

NB I'm writing from my phone at a Gaelic football tournament. I've not
reflected on real code.

Cheers
Mark

On Jul 30, 2016 12:03 PM, "Sam Brannen" notifications@github.com wrote:

@kcooney https://github.com/kcooney, yes, that's correct.

The JUnit 5 team analyzed the existing rules in JUnit 4 and selected ones
that can be supported with current extension APIs in JUnit Jupiter.

JUnit 4 rules not in the above list cannot currently be supported without
some sort of Statement-like extension which is currently not planned for
JUnit Jupiter.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#433 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAImZjvFJJv1pqSW1jJWdxO_SvydbGxiks5qa4PugaJpZM4JUGOo
.

@kcooney
Copy link
Member

kcooney commented Jul 31, 2016

Two points:

  1. There is no need to support ExpectedException for JUnit Jupiter tests. The expectThrows and assertThrows methods are more powerful. In addition, ExpectedException is easy to use incorrectly so we shouldn't encourage it's use for projects that can use lambdas.
  2. This doesn't solve the need for a Rule-like extension point that can be used by JUnit Jupiter tests and JUnit Vintage tests, so deveopers with a large code base can build simple reusable extension points that they can use in both styles of tests while they slowly migrate their tests to JUnit Jupiter. Did the JUnit Lambda team discuss my prototype for such an extension?

@marcphilipp
Copy link
Member

There is no need to support ExpectedException for JUnit Jupiter tests. The expectThrows and assertThrows methods are more powerful. In addition, ExpectedException is easy to use incorrectly so we shouldn't encourage it's use for projects that can use lambdas.

I agree that expectThrows and assertThrows are more powerful. And we will absolutely encourage people to use them.

This doesn't solve the need for a Rule-like extension point that can be used by JUnit Jupiter tests and JUnit Vintage tests, so developers with a large code base can build simple reusable extension points that they can use in both styles of tests while they slowly migrate their tests to JUnit Jupiter.

Indeed, this proposal addresses a different scenario. We have been approached multiple times by developers who want to use Jupiter but are awed by the amount of tests they would need to migrate in order to have old and new tests use the new engine. For such use cases, it will be a lot easier just to replace all the annotations through a script and keep using the most common rules (for now). E.g. replacing ExpectedException with assertThrows is not a simple mechanical change.

Did the JUnit Lambda team discuss my prototype for such an extension?

I'll reply on #169 regarding your prototype.

@kcooney
Copy link
Member

kcooney commented Aug 16, 2016

@marcphilipp instead of special-casing these two rules, have you considered modifying these rules to implement an interface that JUnit Jupiter could support? That would allow third-party developers to potentially update their rules to work with JUnit Jupiter. Of course, then people who want to easily migrate their tests using this migration tool would beed to upgrade to JUnit 4.13 (at least if they wanted the tool to migrate tests using those rules).

It would be quite easy to retrofit these rules to implement my TestFixture interface 😉

mmerdes pushed a commit that referenced this issue Aug 30, 2016
limited support for JUnit 4 rules of type org.junit.rules.ExternalResource
optional dependency of the Jupiter engine on JUnit 4

#433
(cherry picked from commit a20fd0d)
mmerdes pushed a commit that referenced this issue Aug 30, 2016
add tests for the initial rule support.

#433
mmerdes pushed a commit that referenced this issue Aug 30, 2016
new integration test with 2 rules
and after invocation verification

#433
mmerdes pushed a commit that referenced this issue Aug 31, 2016
mmerdes pushed a commit that referenced this issue Aug 31, 2016
Refactor ExternalResourceSupport to prepare for rule-annotated methods
and other TestRules

#433
mmerdes pushed a commit that referenced this issue Sep 1, 2016
Support rule-annotated methods and
make the afterAll-check fail the build if appropriate.

#433
mmerdes pushed a commit that referenced this issue Sep 1, 2016
The ExternalResourceSupport is now composed of the two separately implemented
support classes for method and field support, respectively.
Includes a test to verify the relative order of both cases.

#433
mmerdes pushed a commit that referenced this issue Sep 5, 2016
mmerdes pushed a commit that referenced this issue Sep 5, 2016
mmerdes pushed a commit that referenced this issue Sep 5, 2016
…from JUnit 4

This test would fail correctly if commented in so serves as documentation only.

#433
mmerdes pushed a commit that referenced this issue Sep 6, 2016
mmerdes pushed a commit that referenced this issue Sep 9, 2016
mmerdes pushed a commit that referenced this issue Sep 28, 2016
limited support for JUnit 4 rules of type org.junit.rules.ExternalResource
optional dependency of the Jupiter engine on JUnit 4

#433
(cherry picked from commit a20fd0d)
mmerdes pushed a commit that referenced this issue Sep 28, 2016
add tests for the initial rule support.

#433
mmerdes pushed a commit that referenced this issue Sep 28, 2016
new integration test with 2 rules
and after invocation verification

#433
mmerdes pushed a commit that referenced this issue Sep 28, 2016
mmerdes pushed a commit that referenced this issue Sep 28, 2016
Refactor ExternalResourceSupport to prepare for rule-annotated methods
and other TestRules

#433
mmerdes pushed a commit that referenced this issue Sep 28, 2016
Support rule-annotated methods and
make the afterAll-check fail the build if appropriate.

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
add tests for the initial rule support.

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
new integration test with 2 rules
and after invocation verification

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
Refactor ExternalResourceSupport to prepare for rule-annotated methods
and other TestRules

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
Support rule-annotated methods and
make the afterAll-check fail the build if appropriate.

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
The ExternalResourceSupport is now composed of the two separately implemented
support classes for method and field support, respectively.
Includes a test to verify the relative order of both cases.

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
…from JUnit 4

This test would fail correctly if commented in so serves as documentation only.

#433
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp added a commit that referenced this issue Nov 25, 2016
marcphilipp pushed a commit that referenced this issue Nov 25, 2016
marcphilipp added a commit that referenced this issue Nov 25, 2016
mmerdes pushed a commit that referenced this issue Nov 28, 2016
mmerdes pushed a commit that referenced this issue Nov 29, 2016
mmerdes pushed a commit that referenced this issue Nov 29, 2016
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

5 participants