Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,28 @@ public void postBeforeTest(TestResult testResult, Method memberInfo) {
public void beforeTestFailed(Exception e) throws Exception {
}

/**
* Deprecated. <br>
* Use {@link #preAfterTest(TestResult, TimeRecord, Method)} as it offers more information about the test.
*/
@Deprecated
public void preAfterTest(TestResult testResult, Method memberInfo) throws IOException {
}

public void preAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo) throws IOException {
}

/**
* Deprecated. <br>
* Use {@link #postAfterTest(TestResult, TimeRecord, Method, Throwable)} as it offers more information about the test.
*/
@Deprecated
public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) {
}

public void postAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
}

public void afterTestFailed(Exception e) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,44 @@ public static void beforeTestFailed(Exception e) throws Exception {
}
}

/**
* Deprecated. <br>
* Use {@link #preAfterTest(TestResult, TimeRecord, Method)} as it offers more information about the test.
*/
@Deprecated
public static void preAfterTest(TestResult result, Method memberInfo) throws Exception {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.preAfterTest(result, memberInfo);
}
}

public static void preAfterTest(TestResult result, TimeRecord timeRecord, Method memberInfo) throws Exception {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.preAfterTest(result, timeRecord, memberInfo);
}
}

/**
* Deprecated. <br>
* Use {@link #postAfterTest(TestResult, TimeRecord, Method, Throwable)} as it offers more information about the test.
*/
@Deprecated
public static void postAfterTest(TestResult result, Method memberInfo, Throwable failedTestException) {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.postAfterTest(result, memberInfo, failedTestException);
}
}

public static void postAfterTest(TestResult result, TimeRecord timeRecord, Method memberInfo, Throwable failedTestException) {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
currentObserver.postAfterTest(result, timeRecord, memberInfo, failedTestException);
}
}

public static void afterTestFailed(Exception e) {
for (var currentObserver : PLUGINS) {
if (currentObserver != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Automate The Planet Ltd.
* Author: Miriam Kyoseva
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package solutions.bellatrix.core.plugins;

import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class TimeRecord {
private long startTime;
private long endTime;

public long getDuration() {
return endTime - startTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import solutions.bellatrix.core.plugins.PluginExecutionEngine;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.plugins.TimeRecord;
import solutions.bellatrix.core.plugins.UsesPlugins;

import java.util.ArrayList;
Expand All @@ -26,8 +27,10 @@

@ExtendWith(TestResultWatcher.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(TestDurationWatcher.class)
public class BaseTest extends UsesPlugins {
static final ThreadLocal<TestResult> CURRENT_TEST_RESULT = new ThreadLocal<>();
static final ThreadLocal<TimeRecord> CURRENT_TEST_TIME_RECORD = ThreadLocal.withInitial(TimeRecord::new);
private static final ThreadLocal<Boolean> CONFIGURATION_EXECUTED = new ThreadLocal<>();
private static final List<String> ALREADY_EXECUTED_BEFORE_CLASSES = Collections.synchronizedList(new ArrayList<>());
private TestInfo testInfo;
Expand Down Expand Up @@ -91,7 +94,8 @@ public void afterMethodCore(TestInfo testInfo) {
var testClass = this.getClass();
assert testInfo.getTestMethod().isPresent();
var methodInfo = testClass.getMethod(testInfo.getTestMethod().get().getName(), testInfo.getTestMethod().get().getParameterTypes());
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo); // DEPRECATED, LEFT FOR COMPATIBILITY
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo);
afterEach();
// PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Automate The Planet Ltd.
* Author: Miriam Kyoseva
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package solutions.bellatrix.core.plugins.junit;

import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

public class TestDurationWatcher implements BeforeTestExecutionCallback, AfterTestExecutionCallback {
@Override
public void beforeTestExecution(ExtensionContext context) {
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(System.currentTimeMillis());
}

@Override
public void afterTestExecution(ExtensionContext context) {
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(System.currentTimeMillis());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public void testAborted(ExtensionContext extensionContext, Throwable throwable)
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), throwable);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand All @@ -36,7 +38,9 @@ public void testDisabled(ExtensionContext extensionContext, Optional<String> opt
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), null);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand All @@ -47,7 +51,9 @@ public void testFailed(ExtensionContext extensionContext, Throwable throwable) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), throwable); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), throwable);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand All @@ -58,7 +64,9 @@ public void testSuccessful(ExtensionContext extensionContext) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);

try {
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null);
PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), extensionContext.getTestMethod().get(), null); // DEPRECATED, LEFT FOR COMPATIBILITY

PluginExecutionEngine.postAfterTest(BaseTest.CURRENT_TEST_RESULT.get(), BaseTest.CURRENT_TEST_TIME_RECORD.get(), extensionContext.getTestMethod().get(), null);
} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.testng.annotations.*;
import solutions.bellatrix.core.plugins.PluginExecutionEngine;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.plugins.TimeRecord;
import solutions.bellatrix.core.plugins.UsesPlugins;

import java.util.ArrayList;
Expand All @@ -26,6 +27,7 @@
@Listeners(TestResultListener.class)
public class BaseTest extends UsesPlugins {
static final ThreadLocal<TestResult> CURRENT_TEST_RESULT = new ThreadLocal<>();
static final ThreadLocal<TimeRecord> CURRENT_TEST_TIME_RECORD = ThreadLocal.withInitial(TimeRecord::new);
private static final ThreadLocal<Boolean> CONFIGURATION_EXECUTED = new ThreadLocal<>();
private static final List<String> ALREADY_EXECUTED_BEFORE_CLASSES = Collections.synchronizedList(new ArrayList<>());

Expand Down Expand Up @@ -82,9 +84,12 @@ public void afterMethodCore(ITestResult result) {
try {
var testClass = this.getClass();
var methodInfo = testClass.getMethod(result.getMethod().getMethodName());
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo);
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), methodInfo); // DEPRECATED, LEFT FOR COMPATIBILITY
PluginExecutionEngine.preAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo);
afterEach();
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo, result.getThrowable());
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), methodInfo, result.getThrowable()); // DEPRECATED, LEFT FOR COMPATIBILITY
PluginExecutionEngine.postAfterTest(CURRENT_TEST_RESULT.get(), CURRENT_TEST_TIME_RECORD.get(), methodInfo, result.getThrowable());

} catch (Exception e) {
PluginExecutionEngine.afterTestFailed(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public class TestResultListener implements ITestListener {
@Override
public void onTestSuccess(ITestResult result) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.SUCCESS);
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(result.getStartMillis());
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(result.getEndMillis());
}

@Override
public void onTestFailure(ITestResult result) {
BaseTest.CURRENT_TEST_RESULT.set(TestResult.FAILURE);
BaseTest.CURRENT_TEST_TIME_RECORD.get().setStartTime(result.getStartMillis());
BaseTest.CURRENT_TEST_TIME_RECORD.get().setEndTime(result.getEndMillis());
}
}
23 changes: 23 additions & 0 deletions bellatrix.plugins.jira.zephyr/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>bellatrix</artifactId>
<groupId>solutions.bellatrix</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>bellatrix.plugins.jira.zephyr</artifactId>
<version>1.0</version>

<dependencies>
<dependency>
<groupId>solutions.bellatrix</groupId>
<artifactId>bellatrix.core</artifactId>
<version>1.0</version>
</dependency>

</dependencies>

</project>
Loading