Skip to content

Commit 2f903a4

Browse files
committed
feat(#1218): add further methods to TestListener
Co-authored-by: Thorsten Schlathoelter<[email protected]>
1 parent cb889b2 commit 2f903a4

File tree

9 files changed

+351
-77
lines changed

9 files changed

+351
-77
lines changed

core/citrus-api/src/main/java/org/citrusframework/report/TestListener.java

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,105 @@
2020

2121
/**
2222
* Test listener interface. Listeners invoked on test start, finish, failure, skip, success.
23-
*
2423
*/
2524
public interface TestListener {
2625
/**
27-
* Invoked when test gets started
28-
* @param test
26+
* Invoked when test when a test starts execution
2927
*/
3028
void onTestStart(TestCase test);
3129

3230
/**
33-
* Invoked when test gets finished
34-
* @param test
31+
* @deprecated use on {@link #onTestExecutionEnd(TestCase)}
32+
*/
33+
@Deprecated(forRemoval = true)
34+
default void onTestFinish(TestCase test) {
35+
// Do nothing
36+
}
37+
38+
/**
39+
* Invoked when test execution has ended (after final actions execution and
40+
* before {@link org.citrusframework.container.AfterTest} execution)
41+
*
42+
* @see #onTestEnd(TestCase)
43+
*/
44+
default void onTestExecutionStart(TestCase test) {
45+
onTestFinish(test);
46+
}
47+
48+
49+
/**
50+
* Invoked when test execution has ended (after final actions execution and
51+
* before {@link org.citrusframework.container.AfterTest} execution)
52+
*
53+
* @see #onTestEnd(TestCase)
3554
*/
36-
void onTestFinish(TestCase test);
55+
default void onTestExecutionEnd(TestCase test) {
56+
onTestFinish(test);
57+
}
3758

3859
/**
39-
* Invoked when test finished with success
40-
* @param test
60+
* Invoked at the very end of test execution
61+
*
62+
* @see #onTestFinish(TestCase)
63+
*/
64+
default void onTestEnd(TestCase test) {
65+
// Default implementation does nothing
66+
}
67+
68+
/**
69+
* Invoked when a test finishes successfully
4170
*/
4271
void onTestSuccess(TestCase test);
4372

4473
/**
45-
* Invoked when test finished with failure
46-
* @param test
74+
* Invoked when a test finishes with failure
4775
*/
4876
void onTestFailure(TestCase test, Throwable cause);
4977

5078
/**
51-
* Invoked when test is skipped
52-
* @param test
79+
* Invoked when a test is skipped
5380
*/
5481
void onTestSkipped(TestCase test);
82+
83+
/**
84+
* Invoked when final actions start, only if any exist
85+
*/
86+
default void onFinalActionsStart(TestCase test) {
87+
// Default implementation does nothing
88+
}
89+
90+
/**
91+
* Invoked after final actions have completely finished, only if any exist
92+
*/
93+
default void onFinalActionsEnd(TestCase test) {
94+
// Default implementation does nothing
95+
}
96+
97+
/**
98+
* Invoked when {@link org.citrusframework.container.BeforeTest} execution starts, only if any exist
99+
*/
100+
default void onBeforeTestStart(TestCase test) {
101+
// Default implementation does nothing
102+
}
103+
104+
/**
105+
* Invoked when {@link org.citrusframework.container.BeforeTest} execution ends, only if any exist
106+
*/
107+
default void onBeforeTestEnd(TestCase test) {
108+
// Default implementation does nothing
109+
}
110+
111+
/**
112+
* Invoked when {@link org.citrusframework.container.AfterTest} execution starts, only if any exist
113+
*/
114+
default void onAfterTestStart(TestCase test) {
115+
// Default implementation does nothing
116+
}
117+
118+
/**
119+
* Invoked when {@link org.citrusframework.container.AfterTest} execution ends, only if any exist
120+
*/
121+
default void onAfterTestEnd(TestCase test) {
122+
// Default implementation does nothing
123+
}
55124
}

core/citrus-api/src/main/java/org/citrusframework/report/TestListeners.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,29 @@ public void onTestFailure(TestCase test, Throwable cause) {
3737
}
3838
}
3939

40+
/**
41+
* @deprecated use on {@link #onTestExecutionEnd(TestCase)}
42+
*/
43+
@Deprecated(forRemoval = true)
4044
public void onTestFinish(TestCase test) {
4145
for (TestListener listener : testListeners) {
4246
listener.onTestFinish(test);
4347
}
4448
}
4549

50+
public void onTestExecutionStart(TestCase test) {
51+
for (TestListener listener : testListeners) {
52+
listener.onTestExecutionStart(test);
53+
}
54+
55+
}
56+
57+
public void onTestExecutionEnd(TestCase test) {
58+
for (TestListener listener : testListeners) {
59+
listener.onTestExecutionEnd(test);
60+
}
61+
}
62+
4663
public void onTestSkipped(TestCase test) {
4764
for (TestListener listener : testListeners) {
4865
listener.onTestSkipped(test);
@@ -55,6 +72,48 @@ public void onTestStart(TestCase test) {
5572
}
5673
}
5774

75+
public void onTestFinalization(TestCase test) {
76+
for (TestListener listener : testListeners) {
77+
listener.onTestEnd(test);
78+
}
79+
}
80+
81+
public void onFinalActionsStart(TestCase test) {
82+
for (TestListener listener : testListeners) {
83+
listener.onFinalActionsStart(test);
84+
}
85+
}
86+
87+
public void onFinalActionsEnd(TestCase test) {
88+
for (TestListener listener : testListeners) {
89+
listener.onFinalActionsEnd(test);
90+
}
91+
}
92+
93+
public void onBeforeTestEnd(TestCase test) {
94+
for (TestListener listener : testListeners) {
95+
listener.onBeforeTestEnd(test);
96+
}
97+
}
98+
99+
public void onAfterTestEnd(TestCase test) {
100+
for (TestListener listener : testListeners) {
101+
listener.onAfterTestEnd(test);
102+
}
103+
}
104+
105+
public void onBeforeTestStart(TestCase test) {
106+
for (TestListener listener : testListeners) {
107+
listener.onBeforeTestStart(test);
108+
}
109+
}
110+
111+
public void onAfterTestStart(TestCase test) {
112+
for (TestListener listener : testListeners) {
113+
listener.onAfterTestStart(test);
114+
}
115+
}
116+
58117
public void onTestSuccess(TestCase test) {
59118
for (TestListener listener : testListeners) {
60119
listener.onTestSuccess(test);
@@ -70,7 +129,6 @@ public void addTestListener(TestListener listener) {
70129

71130
/**
72131
* Obtains the testListeners.
73-
* @return
74132
*/
75133
public List<TestListener> getTestListeners() {
76134
return testListeners;

core/citrus-api/src/main/java/org/citrusframework/report/TestReporters.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void onTestStart(TestCase test) {
8080
}
8181

8282
@Override
83-
public void onTestFinish(TestCase test) {
83+
public void onTestExecutionEnd(TestCase test) {
8484
if (nonNull(test.getTestResult())) {
8585
testResults.addResult(test.getTestResult());
8686
}
@@ -108,35 +108,27 @@ public void addTestReporter(TestReporter testReporter) {
108108

109109
/**
110110
* Obtains the testReporters.
111-
*
112-
* @return
113111
*/
114112
public List<TestReporter> getTestReporters() {
115113
return unmodifiableList(testReporters);
116114
}
117115

118116
/**
119117
* Obtains the autoClear.
120-
*
121-
* @return
122118
*/
123119
public boolean isAutoClear() {
124120
return autoClear;
125121
}
126122

127123
/**
128124
* Specifies the autoClear.
129-
*
130-
* @param autoClear
131125
*/
132126
public void setAutoClear(boolean autoClear) {
133127
this.autoClear = autoClear;
134128
}
135129

136130
/**
137131
* Gets the testResults.
138-
*
139-
* @return
140132
*/
141133
public TestResults getTestResults() {
142134
return testResults;

core/citrus-api/src/test/java/org/citrusframework/report/TestReportersTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ private void verifyGenerateReport(Runnable invocation) {
7777
}
7878

7979
@Test
80-
public void onTestFinishAddsTestResultToList() {
80+
public void onTestExecutionEndAddsTestResultToList() {
8181
var testResultMock = mock(TestResult.class);
8282
doReturn(testResultMock).when(testCaseMock).getTestResult();
8383

84-
fixture.onTestFinish(testCaseMock);
84+
fixture.onTestExecutionEnd(testCaseMock);
8585

8686
var testResults = fixture.getTestResults().asList();
8787
assertEquals(1, testResults.size());
8888
assertEquals(testResultMock, testResults.get(0));
8989
}
9090

9191
@Test
92-
public void onTestFinishIgnoresNullTestResult() {
92+
public void onTestExecutionEndIgnoresNullTestResult() {
9393
doReturn(null).when(testCaseMock).getTestResult();
9494

95-
fixture.onTestFinish(testCaseMock);
95+
fixture.onTestExecutionEnd(testCaseMock);
9696

9797
var testResults = fixture.getTestResults().asList();
9898
assertEquals(0, testResults.size());

0 commit comments

Comments
 (0)