-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Document scope of applicability for TestWatcher
implementations
#3234
Comments
@Disabled
events for test templates are not supplied to TestWatcher
I have confirmed that disabled events are not supplied to a The following can be used to reproduce the issue. class WatcherTests {
@RegisterExtension
Extension watcher = new TestWatcher() {
@Override
public void testSuccessful(ExtensionContext context) {
System.err.println("SUCCESSFUL: " + context.getRequiredTestMethod().getName());
}
@Override
public void testDisabled(ExtensionContext context, Optional<String> reason) {
System.err.println("DISABLED : " + context.getRequiredTestMethod().getName());
}
};
@Disabled
@Test
void test() {
}
@Disabled
@RepeatedTest(2)
void repeatedTest() {
}
@Disabled
@ParameterizedTest
@ValueSource(strings = { "a", "b" })
void parameterizedTest(String s) {
}
} Since the documentation states the following, I am labeling this as a bug.
Thanks for raising the issue, @wazzeps. |
@Disabled
events for test templates are not supplied to TestWatcher
@Disabled
events for @TestTemplate
methods are not supplied to TestWatcher
Oops. I retract that. Everything works fine if the For example, changing the declaration to @RegisterExtension
static Extension watcher = new TestWatcher() { // ... I am therefore repurposing this issue to improve the documentation for |
@Disabled
events for @TestTemplate
methods are not supplied to TestWatcher
TestWatcher
implementations
If I understand correctly, using an extension with @ExtendWith(TestWatcherImpl.class)
public class SomeTest { In this case |
I am not able to reproduce that. When I execute the following, it prints out:
@ExtendWith(WatcherTests.MyWatcher.class)
class WatcherTests {
static class MyWatcher implements TestWatcher{
@Override
public void testSuccessful(ExtensionContext context) {
System.err.println("SUCCESSFUL: " + context.getRequiredTestMethod().getName());
}
@Override
public void testDisabled(ExtensionContext context, Optional<String> reason) {
System.err.println("DISABLED : " + context.getRequiredTestMethod().getName());
}
}
@Disabled
@Test
void test() {
}
@Disabled
@RepeatedTest(2)
void repeatedTest() {
}
@Disabled
@ParameterizedTest
@ValueSource(strings = { "a", "b" })
void parameterizedTest(String s) {
}
} |
In my case, I implemented TestWatcher in a separate class
and then
|
That doesn't make a difference. A top-level class exhibits the same behavior as a static nested class. For example, the following also prints:
@ExtendWith(MyWatcher.class)
public class WatcherTests {
@Disabled
@Test
void test() {
}
@Disabled
@RepeatedTest(2)
void repeatedTest() {
}
@Disabled
@ParameterizedTest
@ValueSource(strings = { "a", "b" })
void parameterizedTest(String s) {
}
}
class MyWatcher implements TestWatcher {
@Override
public void testSuccessful(ExtensionContext context) {
System.err.println("SUCCESSFUL: " + context.getRequiredTestMethod().getName());
}
@Override
public void testDisabled(ExtensionContext context, Optional<String> reason) {
System.err.println("DISABLED : " + context.getRequiredTestMethod().getName());
}
} |
Both of your examples end with DISABLED : parameterizedTest. Could you please check what happens if the test with @ParameterizedTest runs first? |
It doesn't make a difference if the parameterized test runs first. @ExtendWith(WatcherTests.MyWatcher.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class WatcherTests {
static class MyWatcher implements TestWatcher {
@Override
public void testSuccessful(ExtensionContext context) {
System.err.println("SUCCESSFUL: " + context.getRequiredTestMethod().getName());
}
@Override
public void testDisabled(ExtensionContext context, Optional<String> reason) {
System.err.println("DISABLED : " + context.getRequiredTestMethod().getName());
}
}
@Order(1)
@Disabled
@ParameterizedTest
@ValueSource(strings = { "a", "b" })
void parameterizedTest(String s) {
}
@Order(2)
@Disabled
@Test
void test() {
}
@Order(3)
@Disabled
@RepeatedTest(2)
void repeatedTest() {
}
} Here's the result:
|
Interesting. I got different results.
then
then
|
If you annotate a test class with
The output is empty in such case. |
Good point. 👍 The documentation already states the following.
So that's similar in nature to the |
TestWatcher
implementationsTestWatcher
implementations
Referring to #2560
Steps to reproduce
With
TestWatcher
implementationExpected: 2 outputs "DISABLED"
Actual: no output, testDisabled method wasn't called
Context
The text was updated successfully, but these errors were encountered: