Skip to content

Commit b294e99

Browse files
committed
Include TestWatcher example
1 parent 6d984b0 commit b294e99

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* (C) Copyright 2025 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia;
18+
19+
import java.util.Optional;
20+
21+
import org.junit.jupiter.api.extension.ExtensionContext;
22+
import org.junit.jupiter.api.extension.TestWatcher;
23+
24+
public class MyWatcher implements TestWatcher {
25+
26+
@Override
27+
public void testDisabled(ExtensionContext context,
28+
Optional<String> reason) {
29+
System.out.println("Test disabled: " + reason.get());
30+
}
31+
32+
@Override
33+
public void testSuccessful(ExtensionContext context) {
34+
System.out.println("Test successful");
35+
}
36+
37+
@Override
38+
public void testAborted(ExtensionContext context, Throwable cause) {
39+
System.out.println("Test aborted " + cause);
40+
}
41+
42+
@Override
43+
public void testFailed(ExtensionContext context, Throwable cause) {
44+
System.out.println("Test failed " + cause);
45+
}
46+
47+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* (C) Copyright 2025 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Assumptions;
21+
import org.junit.jupiter.api.Disabled;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
25+
@Disabled("To avoid break CI")
26+
@ExtendWith(MyWatcher.class)
27+
public class WatcherTest {
28+
29+
@Test
30+
public void successTest() {
31+
Assertions.assertTrue(true);
32+
}
33+
34+
@Test
35+
public void failTest() {
36+
Assertions.fail("Force failure");
37+
}
38+
39+
@Disabled
40+
@Test
41+
public void disabledTest() {
42+
Assertions.fail("This won't happend");
43+
}
44+
45+
@Test
46+
public void skippedTest() {
47+
Assumptions.assumeTrue(false);
48+
}
49+
50+
}

0 commit comments

Comments
 (0)