-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Split JUnit 5 OutputCapture into extension and captured output #17029
Comments
I have another |
@wilkinsona I've just pushed the updated code. Let me know if you think any additional changes are needed. |
The javadoc for @RegisterExtension
CapturedOutput output = OutputExtension.capture(); I think it would be more idiomatic to use it declaratively at the class level: @ExtendWith(OutputCaptureExtension.class) Its @Test
public void ofWhenContainsDeprecatedCharsLogsWarning(CapturedOutput capturedOutput) {
EndpointId.resetLoggedWarnings();
EndpointId.of("foo-bar");
assertThat(capturedOutput).contains(
"Endpoint ID 'foo-bar' contains invalid characters, please migrate to a valid format");
} |
Having looked more closely, the extension can already be used declaratively so the changes I tried to describe above become a matter of enforcing that. I think that's the right thing to do as it's more idiomatic. It also means that we can reduce the surface area of the API a little as the The first commit in this branch contains the changes that I think we should make. I explored splitting the capturing of the output and making that output available to tests into two separate classes in a general purpose |
I've pushed a third refinement that avoids this problem. It repackages things into an |
I like the the fact there's no dependency on the JUnit API's, but it's a bit annoying that you end up adding so many additional arguments to the tests. I guess you could always use constructor injection to setup a private instance. The JUnit API is slightly annoying in that when you use |
Ask, and ye shall receive! junit-team/junit5#1908 😉 |
I have made additional proposals in #17049. |
Re-opening again as |
The thread-safety problem was fixed as part of b18fffa. |
The new
OutputCapture
class introduced in #14738 currently acts as both the extension and the captured output. This has the unfortunate side-effect of exposing JUnit callback methods to users of the API when really only JUnit cares about them. I think it's possible to split the class and offer an extension for JUnit to use as well as a user-facing class that represents the output captured by the extension.The text was updated successfully, but these errors were encountered: