Skip to content

Commit

Permalink
Merge pull request #210 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Apr 4, 2024
2 parents 9cad8d8 + e80bda3 commit 13bc72a
Show file tree
Hide file tree
Showing 20 changed files with 459 additions and 43 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ on:
branches:
- '*'
- '!master'
- '!v4-hotfix'
- '!v5-testng6'
paths-ignore:
- README.md
Expand All @@ -28,7 +27,7 @@ on:
pull_request:
branches:
- master
- v4-hotfix
- develop
- v5-testng6

jobs:
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# Changelog

## [Unreleased]
### Added
- `@Description` annotation support, by @oleksandr-fomenko
- `@DisplayName` annotation support, by @oleksandr-fomenko
- Putting last error logs of tests to Items' description, by @utdacc
### Changed
- Client version updated on [5.2.13](https://github.com/reportportal/client-java/releases/tag/5.2.13), by @HardNorth
### Removed
- `TestNG` dependency marked as `compileOnly`, by @HardNorth
- JSR-305 dependency, by @HardNorth

## [5.4.1]
### Changed
- Move Okhttp3 to test dependencies, by @HardNorth
- Remove `commons-model` dependency to rely on `clinet-java` exclusions in security fixes, by @HardNorth
- Client version updated on [5.2.4](https://github.com/reportportal/client-java/releases/tag/5.2.4), by @HardNorth
### Removed
- `commons-model` dependency to rely on `clinet-java` exclusions in security fixes, by @HardNorth

## [5.4.0]
### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A TestNG reporter that uploads the results to a ReportPortal server.
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-testng.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-testng)
[![CI Build](https://github.com/reportportal/agent-java-testNG/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-testNG/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/agent-java-testNG/branch/develop/graph/badge.svg?token=CshHrWt7sS)](https://codecov.io/gh/reportportal/agent-java-testNG)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
[![Join Slack chat!](https://img.shields.io/badge/slack-join-brightgreen.svg)](https://slack.epmrpp.reportportal.io/)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)

Expand Down
2 changes: 1 addition & 1 deletion README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A TestNG reporter that uploads the results to a ReportPortal server.
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-testng.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-testng)
[![CI Build](https://github.com/reportportal/agent-java-testNG/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-testNG/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/agent-java-testNG/branch/develop/graph/badge.svg?token=CshHrWt7sS)](https://codecov.io/gh/reportportal/agent-java-testNG)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
[![Join Slack chat!](https://img.shields.io/badge/slack-join-brightgreen.svg)](https://slack.epmrpp.reportportal.io/)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)

Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ project.ext.limits = [

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

repositories {
mavenCentral()
}

dependencies {
api 'com.epam.reportportal:client-java:5.2.4'
api 'com.google.code.findbugs:jsr305:3.0.2'
api 'com.epam.reportportal:client-java:5.2.13'

implementation 'org.testng:testng:7.9.0'
compileOnly "org.testng:testng:${testng_version}"
implementation 'org.slf4j:slf4j-api:2.0.4'

testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2'
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.6'

testImplementation "org.testng:testng:${testng_version}"
testImplementation("org.junit.platform:junit-platform-runner:${junit5_runner_version}") {
exclude module: 'junit'
}
Expand All @@ -58,7 +60,7 @@ dependencies {
testImplementation "org.mockito:mockito-junit-jupiter:${mockito_version}"
testImplementation 'ch.qos.logback:logback-classic:1.4.12'

testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0'
testImplementation 'com.epam.reportportal:logger-java-logback:5.2.2'

testImplementation 'org.apache.commons:commons-io:1.3.2'
testImplementation 'com.ibm.icu:icu4j:67.1'
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ description=TestNG integration for ReportPortal
junit5_version=5.6.3
junit5_runner_version=1.6.3
mockito_version=3.3.3
testng_version=7.9.0
scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts
scripts_branch=master
excludeTests=
27 changes: 27 additions & 0 deletions src/main/java/com/epam/reportportal/testng/TestNGService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.epam.reportportal.testng;

import com.epam.reportportal.annotations.Description;
import com.epam.reportportal.annotations.DisplayName;
import com.epam.reportportal.annotations.ParameterKey;
import com.epam.reportportal.annotations.TestCaseId;
import com.epam.reportportal.annotations.attribute.Attributes;
Expand All @@ -35,6 +37,7 @@
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
import com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
import io.reactivex.Maybe;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.testng.*;
import org.testng.annotations.Factory;
Expand Down Expand Up @@ -92,6 +95,7 @@ public class TestNGService implements ITestNGService {
public static final String RP_RETRY = "rp_retry";
public static final String RP_METHOD_TYPE = "rp_method_type";
public static final String NULL_VALUE = "NULL";
public static final String DESCRIPTION_ERROR_FORMAT = "%s\nError: \n%s";
public static final TestItemTree ITEM_TREE = new TestItemTree();

private final Map<Object, Queue<Pair<Maybe<String>, FinishTestItemRQ>>> BEFORE_METHOD_TRACKER = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -372,6 +376,9 @@ protected FinishTestItemRQ buildFinishTestMethodRq(@Nonnull ItemStatus status, @
FinishTestItemRQ rq = new FinishTestItemRQ();
rq.setEndTime(new Date(testResult.getEndMillis()));
rq.setStatus(status.name());
if (!testResult.isSuccess() && ItemStatus.SKIPPED != status) {
rq.setDescription(getLogMessage(testResult));
}
return rq;
}

Expand Down Expand Up @@ -709,6 +716,10 @@ protected String createConfigurationDescription(ITestResult testResult) {
* @return Test/Step Name being sent to ReportPortal
*/
protected String createStepName(ITestResult testResult) {
var methodDisplayNameOptional = getMethodAnnotation(DisplayName.class, testResult);
if(methodDisplayNameOptional.isPresent()){
return methodDisplayNameOptional.get().value();
}
String testStepName = testResult.getTestName();
return testStepName == null ? testResult.getMethod().getMethodName() : testStepName;
}
Expand All @@ -720,6 +731,10 @@ protected String createStepName(ITestResult testResult) {
* @return Test/Step Description being sent to ReportPortal
*/
protected String createStepDescription(ITestResult testResult) {
var methodDescriptionOptional = getMethodAnnotation(Description.class, testResult);
if(methodDescriptionOptional.isPresent()){
return methodDescriptionOptional.get().value();
}
return testResult.getMethod().getDescription();
}

Expand Down Expand Up @@ -787,4 +802,16 @@ Maybe<String> getConfigParent(ITestResult testResult, TestMethodType type) {
}
return parentId;
}

/**
* Extension point to customize test step description with error message
* @param testResult TestNG's testResult context
* @return Test/Step Description being sent to ReportPortal
*/
private String getLogMessage(ITestResult testResult) {
return String.format(DESCRIPTION_ERROR_FORMAT,
createStepDescription(testResult),
ExceptionUtils.getStackTrace(testResult.getThrowable()))
.trim();
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/aop-ajc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-->

<aspectj>
<weaver options="-nowarn -Xset:weaveJavaPackages=false,weaveJavaxPackages=false" />
<aspects>
<aspect name="com.epam.reportportal.aspect.StepAspect"/>
</aspects>
Expand Down
84 changes: 52 additions & 32 deletions src/test/java/com/epam/reportportal/testng/BuildStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.epam.reportportal.testng;

import com.epam.reportportal.annotations.Description;
import com.epam.reportportal.annotations.DisplayName;
import com.epam.reportportal.annotations.ParameterKey;
import com.epam.reportportal.annotations.TestCaseId;
import com.epam.reportportal.annotations.TestCaseIdKey;
Expand Down Expand Up @@ -43,7 +45,7 @@
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

/**
* @author Pavel Bortnik
Expand Down Expand Up @@ -79,6 +81,17 @@ public void testMethodName() {
assertThat("Incorrect test item name", rq.getName(), is(DEFAULT_NAME));
}

@Test
public void testMethodNameDisplayNameAnnotated() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Method method = getTestMethodsExampleByName("testDisplayNameAnnotation");
when(constructorOrMethod.getMethod()).thenReturn(method);
StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
assertThat("Incorrect test item name", rq.getName(), is(DEFAULT_NAME_DISPLAY_NAME_ANNOTATION));
}

@Test
public void testDescription() {
when(testResult.getMethod()).thenReturn(testNGMethod);
Expand All @@ -89,18 +102,24 @@ public void testDescription() {
assertThat("Incorrect test description", rq.getDescription(), is(DEFAULT_DESCRIPTION));
}

@Test
public void testAnnotatedDescriptionAnnotated() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Method method = getTestMethodsExampleByName("testDescriptionAnnotation");
when(constructorOrMethod.getMethod()).thenReturn(method);
StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
assertThat("Incorrect test description", rq.getDescription(), is(DEFAULT_ANNOTATION_DESCRIPTION));
}

@Test
public void testParameters() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Method[] methods = TestMethodsExamples.class.getDeclaredMethods();
Method method = null;
for (Method m : methods) {
if (m.getName().contains("parametersAnnotation")) {
method = m;
}
}
Method method = getTestMethodsExampleByName("parametersAnnotation");

when(constructorOrMethod.getMethod()).thenReturn(method);
when(testResult.getParameters()).thenReturn(new Object[] { "param_0", "param_1" });
StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
Expand All @@ -118,13 +137,7 @@ public void testParametersDataProvider_DefaultKey() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Method[] methods = TestMethodsExamples.class.getDeclaredMethods();
Method method = null;
for (Method m : methods) {
if (m.getName().contains("dataProviderWithoutKey")) {
method = m;
}
}
Method method = getTestMethodsExampleByName("dataProviderWithoutKey");

when(constructorOrMethod.getMethod()).thenReturn(method);
when(testResult.getParameters()).thenReturn(new Object[] { "param_0", "param_1" });
Expand All @@ -142,13 +155,7 @@ public void testParametersDataProvider_ProvidedKey() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Method[] methods = TestMethodsExamples.class.getDeclaredMethods();
Method method = null;
for (Method m : methods) {
if (m.getName().contains("dataProviderWithParameterKey")) {
method = m;
}
}
Method method = getTestMethodsExampleByName("dataProviderWithParameterKey");

when(constructorOrMethod.getMethod()).thenReturn(method);
when(testResult.getParameters()).thenReturn(new Object[] { "param_0", "param_1" });
Expand Down Expand Up @@ -222,6 +229,7 @@ public void testRetryAnalyzerNull() {
@Test
public void testBuildFinishRQ() {
when(testResult.getEndMillis()).thenReturn(DEFAULT_TIME);
when(testResult.isSuccess()).thenReturn(true);
FinishTestItemRQ rq = testNGService.buildFinishTestMethodRq(ItemStatus.PASSED, testResult);
assertThat("Incorrect end time", rq.getEndTime().getTime(), is(DEFAULT_TIME));
assertThat("Incorrect status", rq.getStatus(), is(ItemStatus.PASSED.name()));
Expand Down Expand Up @@ -300,13 +308,10 @@ public void testCaseId_fromAnnotation() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Optional<Method> methodOptional = Arrays.stream(TestMethodsExamples.class.getDeclaredMethods())
.filter(it -> it.getName().equals("testCaseId"))
.findFirst();
assertTrue(methodOptional.isPresent());
Method method = getTestMethodsExampleByName("testCaseId");
String expectedCodeRef = "com.test.BuildStepTest.codeRefTest";

when(constructorOrMethod.getMethod()).thenReturn(methodOptional.get());
when(constructorOrMethod.getMethod()).thenReturn(method);
when(testResult.getMethod().getQualifiedName()).thenReturn(expectedCodeRef);

StartTestItemRQ request = testNGService.buildStartStepRq(testResult);
Expand All @@ -320,14 +325,11 @@ public void testCaseId_fromAnnotationParametrized() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Optional<Method> methodOptional = Arrays.stream(TestMethodsExamples.class.getDeclaredMethods())
.filter(it -> it.getName().equals("testCaseIdParameterized"))
.findFirst();
assertTrue(methodOptional.isPresent());
Method method = getTestMethodsExampleByName("testCaseIdParameterized");
String expectedCodeRef = "com.test.BuildStepTest.codeRefTest";
String expectedParam = "test-case-id-key";

when(constructorOrMethod.getMethod()).thenReturn(methodOptional.get());
when(constructorOrMethod.getMethod()).thenReturn(method);
when(testResult.getMethod().getQualifiedName()).thenReturn(expectedCodeRef);
when(testResult.getParameters()).thenReturn(new Object[] { expectedParam });

Expand All @@ -337,6 +339,14 @@ public void testCaseId_fromAnnotationParametrized() {
assertEquals(expectedParam, request.getTestCaseId());
}

private Method getTestMethodsExampleByName(String methodName){
Optional<Method> methodOptional = Arrays.stream(TestMethodsExamples.class.getDeclaredMethods())
.filter(it -> it.getName().equals(methodName))
.findFirst();
assertTrue(methodOptional.isPresent());
return methodOptional.get();
}

private static class TestMethodsExamples {
@Ignore
@org.testng.annotations.Test(dataProvider = "dp")
Expand Down Expand Up @@ -370,6 +380,16 @@ private void testCaseId() {
private void testCaseIdParameterized(@TestCaseIdKey String param) {
//just for testing providing annotation
}

@Description(DEFAULT_ANNOTATION_DESCRIPTION)
private void testDescriptionAnnotation() {
//just for testing providing annotation
}

@DisplayName(DEFAULT_NAME_DISPLAY_NAME_ANNOTATION)
private void testDisplayNameAnnotation() {
//just for testing providing annotation
}
}

}
2 changes: 2 additions & 0 deletions src/test/java/com/epam/reportportal/testng/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public class Constants {
static final String BASIC_URL = "basic_url";
static final String DEFAULT_UUID = "default_uuid";
static final String DEFAULT_NAME = "default_name";
static final String DEFAULT_NAME_DISPLAY_NAME_ANNOTATION = "default_display_name";
static final String DEFAULT_PROJECT = "default_project";
static final ItemAttributesRQ ATTRIBUTE = new ItemAttributesRQ("key", "value");
static final Set<ItemAttributesRQ> ATTRIBUTES = new HashSet<>(Collections.singleton(ATTRIBUTE));
static final Mode MODE = Mode.DEFAULT;
static final String DEFAULT_DESCRIPTION = "default_description";
static final String DEFAULT_ANNOTATION_DESCRIPTION = "default_annotation_description";
static final Long DEFAULT_TIME = 1515594836210L;

}
Loading

0 comments on commit 13bc72a

Please sign in to comment.