-
Notifications
You must be signed in to change notification settings - Fork 738
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 JUnit Jupiter extension analogous to JUnitRestDocumentation #296
Comments
If Spring REST Docs is not able or willing to provide built-in integration with milestone releases of JUnit Jupiter, another option would be to provide an example implementation in the wiki as an interim solution for early adopters of JUnit 5. |
@wilkinsona, I'd be glad to consult you on the implementation. 😉 |
Rather than being able to implement Arguably, assuming my analysis above is accurate, it's also a step backwards for users. This arrangement will mean that the output directory has to be a literal value and can't be something that's determined at runtime. More generally, it also appears to limit the types that can be passed into an extension to those that are legal for an annotation attribute. |
You rock, man! Seriously... I could hug you right now. Now... before you get scared, let me explain my elation. 😉 Thanks to your in-depth analysis and spot-on constructive criticism, I have had an epiphany of sorts! What if I told you, you'll be able to replace this in JUnit 4 tests: @Rule
public JUnitRestDocumentation restDocumentation =
new JUnitRestDocumentation("target/generated-snippets"); ... with the following in JUnit Jupiter tests: @ExtendWith
RestDocumentationExtension restDocumentation =
new RestDocumentationExtension("target/generated-snippets"); ❓ Now, as you correctly deduced, the above is currently not possible in JUnit Jupiter since extensions can presently only be registered on classes or methods. But... I am going to do my best to ensure that JUnit Jupiter also supports the JUnit 4 registration style for rules declared as fields, even if the implementation style differs. What would you say to that? Cheers, Sam |
FYI: I overhauled and partially repurposed junit-team/junit5#416 to address the concerns raised here. |
Just my 2cts regarding this.... From a user's perspective it felt wrong having to (usually repeatedly) specify the output directory within the tests, like it is right now. Why should all of my tests care about this property? To me an annotation value that can be controlled from my (maven/gradle) build would be a better-suited place, making it some kind of shared concern of all my REST tests. After all it's my build tool that picks up these artefacts later on.
|
I'm not proposing that However, having said that, since Spring REST Docs uses Spring... it's certainly conceivable that the |
I, too, dislike the repetition.
That would be ideal. An alternative is to use a base class for all REST tests that defines the rule and the output directory.
True, but the output when a test is run in the IDE needs to be written somewhere. I want that to be the same place as is used when the tests are run via Maven or Gradle. I've struggled with this for a while, but I have some ideas now on how it can be improved and use a convention-based approach. However, it will still be necessary to allow the convention to be overridden which is where the discussion above will come in useful. |
Thanks, @sbrannen. I'll look forward to my hug the next time I see you. That looks much better from REST Docs' perspective. The tests will require access to the instance of the extension so would need to declare the field anyway. I think that having the |
Well, with JUnit Jupiter that's actually no longer a requirement like it is with JUnit 4. The instance of the Having said that, however, having the
I agree. |
FYI: support for programmatic extension registration in JUnit Jupiter will now be addressed in junit-team/junit5#497. |
Is there a workaround for this currently? |
An extension that delegates to |
Thanks. The I've posted it back to the question. If you see that I'm doing something absurd, please point it out. |
@ericjturley. Nothing absurd there at all. Thanks for sharing what you've done. I'm looking forward to junit-team/junit5#497 in JUnit 5 M4 as it'll allow an extension to be used as a field. |
As mentioned in the Spring REST docs: How to migrate Rule to JUnit 5 discussion on Stack Overflow, it is possible to migrate existing Spring REST Docs tests based on JUnit 4 to JUnit Jupiter (JUnit 5); however, there is currently no built-in support analogous to the
JUnitRestDocumentation
TestRule
for JUnit 4.I propose that REST Docs should introduce a JUnit Jupiter extension analogous to the
JUnitRestDocumentation
TestRule
. This extension should implement theBeforeEachCallback
andAfterEachCallback
APIs from JUnit Jupiter. Alternatively, the extension could implement theBeforeTestExecutionCallback
andAfterTestExecutionCallback
APIs, depending on the exact needs of Spring REST Docs.The text was updated successfully, but these errors were encountered: