From 12187baa96c26a76bbaf6b97e4114d6c19397129 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 11 Oct 2024 09:38:38 +0300 Subject: [PATCH 1/4] Remove code references on Test level to fix reruns --- .../reportportal/testng/TestNGService.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/epam/reportportal/testng/TestNGService.java b/src/main/java/com/epam/reportportal/testng/TestNGService.java index 5953e46..77431c3 100644 --- a/src/main/java/com/epam/reportportal/testng/TestNGService.java +++ b/src/main/java/com/epam/reportportal/testng/TestNGService.java @@ -75,16 +75,14 @@ * TestNG service implements operations for interaction ReportPortal */ public class TestNGService implements ITestNGService { - private static final Set BEFORE_METHODS = Stream.of( - TestMethodType.BEFORE_TEST, + private static final Set BEFORE_METHODS = Stream.of(TestMethodType.BEFORE_TEST, TestMethodType.BEFORE_SUITE, TestMethodType.BEFORE_GROUPS, TestMethodType.BEFORE_CLASS, TestMethodType.BEFORE_METHOD ).collect(Collectors.toSet()); private static final String AGENT_PROPERTIES_FILE = "agent.properties"; - private static final Set TESTNG_INVOKERS = Stream.of( - "org.testng.internal.TestInvoker", + private static final Set TESTNG_INVOKERS = Stream.of("org.testng.internal.TestInvoker", "org.testng.internal.invokers.TestInvoker" ).collect(Collectors.toSet()); private static final Predicate IS_RETRY_ELEMENT = e -> TESTNG_INVOKERS.contains(e.getClassName()) @@ -284,7 +282,7 @@ protected StartTestItemRQ buildStartConfigurationRq(@Nonnull ITestResult testRes @Override public void startConfiguration(ITestResult testResult) { - if(ofNullable(getAttribute(testResult, RP_ID)).isPresent()) { + if (ofNullable(getAttribute(testResult, RP_ID)).isPresent()) { // Already started, E.G. SkipException is thrown return; } @@ -471,13 +469,11 @@ public void finishTestMethod(ItemStatus status, ITestResult testResult) { if (ItemStatus.FAILED == status && (TestMethodType.BEFORE_METHOD == type || TestMethodType.BEFORE_CLASS == type)) { SKIPPED_STATUS_TRACKER.put(instance, Boolean.TRUE); } - if (ItemStatus.SKIPPED == status - && (SKIPPED_STATUS_TRACKER.containsKey(instance) - || (TestMethodType.BEFORE_METHOD == type && getAttribute(testResult, RP_RETRY) != null)) - ) { + if (ItemStatus.SKIPPED == status && (SKIPPED_STATUS_TRACKER.containsKey(instance) || (TestMethodType.BEFORE_METHOD == type + && getAttribute(testResult, RP_RETRY) != null))) { rq.setIssue(Launch.NOT_ISSUE); } - if(ItemStatus.SKIPPED == status && BEFORE_METHODS.contains(type) && testResult.getThrowable() != null) { + if (ItemStatus.SKIPPED == status && BEFORE_METHODS.contains(type) && testResult.getThrowable() != null) { sendReportPortalMsg(testResult); SKIPPED_STATUS_TRACKER.put(instance, Boolean.TRUE); } @@ -533,13 +529,9 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull ITestContext testContext StartTestItemRQ rq = new StartTestItemRQ(); Set attributes = rq.getAttributes() == null ? new HashSet<>() : new HashSet<>(rq.getAttributes()); rq.setAttributes(attributes); - ofNullable(testContext.getCurrentXmlTest()).map(XmlTest::getXmlClasses).ifPresent(xmlClasses -> xmlClasses.forEach(xmlClass -> { - String className = xmlClass.getName(); - String codeRef = rq.getCodeRef(); - rq.setCodeRef(codeRef == null ? className : codeRef + ";" + className); - ofNullable(xmlClass.getSupportClass()).map(c -> c.getAnnotation(Attributes.class)) - .ifPresent(a -> attributes.addAll(AttributeParser.retrieveAttributes(a))); - })); + ofNullable(testContext.getCurrentXmlTest()).map(XmlTest::getXmlClasses) + .ifPresent(xmlClasses -> xmlClasses.forEach(xmlClass -> ofNullable(xmlClass.getSupportClass()).map(c -> c.getAnnotation( + Attributes.class)).ifPresent(a -> attributes.addAll(AttributeParser.retrieveAttributes(a))))); rq.setName(testContext.getName()); rq.setStartTime(testContext.getStartDate()); rq.setType("TEST"); @@ -719,7 +711,7 @@ protected String createConfigurationDescription(ITestResult testResult) { */ protected String createStepName(ITestResult testResult) { var methodDisplayNameOptional = getMethodAnnotation(DisplayName.class, testResult); - if(methodDisplayNameOptional.isPresent()){ + if (methodDisplayNameOptional.isPresent()) { return methodDisplayNameOptional.get().value(); } String testStepName = testResult.getTestName(); @@ -734,7 +726,7 @@ protected String createStepName(ITestResult testResult) { */ protected String createStepDescription(ITestResult testResult) { var methodDescriptionOptional = getMethodAnnotation(Description.class, testResult); - if(methodDescriptionOptional.isPresent()){ + if (methodDescriptionOptional.isPresent()) { return methodDescriptionOptional.get().value(); } return testResult.getMethod().getDescription(); @@ -747,8 +739,13 @@ private TestCaseIdEntry getTestCaseId(@Nonnull String codeRef, @Nonnull ITestRes List parameters = ofNullable(testResult.getParameters()).map(Arrays::asList).orElse(null); TestCaseIdEntry id = getMethodAnnotation(TestCaseId.class, testResult - ).flatMap(a -> ofNullable(method).map(m -> TestCaseIdUtils.getTestCaseId(a, m, codeRef, parameters, instance))) - .orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters)); + ).flatMap(a -> ofNullable(method).map(m -> TestCaseIdUtils.getTestCaseId( + a, + m, + codeRef, + parameters, + instance + ))).orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters)); return id == null ? null : id.getId().endsWith("[]") ? new TestCaseIdEntry(id.getId().substring(0, id.getId().length() - 2)) : id; } @@ -807,12 +804,14 @@ Maybe getConfigParent(ITestResult testResult, TestMethodType type) { /** * 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) { String error = String.format(DESCRIPTION_ERROR_FORMAT, ExceptionUtils.getStackTrace(testResult.getThrowable())).trim(); return ofNullable(createStepDescription(testResult)).filter(StringUtils::isNotBlank) - .map(description -> MarkdownUtils.asTwoParts(description, error)).orElse(error); + .map(description -> MarkdownUtils.asTwoParts(description, error)) + .orElse(error); } } From c73307ff1f75b7e15c0b7a1f57bcac7cf78b7b90 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 11 Oct 2024 09:46:09 +0300 Subject: [PATCH 2/4] Client version update --- CHANGELOG.md | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de2b4cd..4212f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] ### Changed -- Client version updated on [5.2.14](https://github.com/reportportal/client-java/releases/tag/5.2.14), by @HardNorth +- Client version updated on [5.2.15](https://github.com/reportportal/client-java/releases/tag/5.2.15), by @HardNorth - Format of last error log of test in item description was updated, by @HardNorth ## [5.4.2] diff --git a/build.gradle b/build.gradle index 1db06c1..91789c3 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.2.14' + api 'com.epam.reportportal:client-java:5.2.15' compileOnly "org.testng:testng:${testng_version}" implementation 'org.slf4j:slf4j-api:2.0.4' From 0eeb08316e0fd660b1eb87236a650cf12c36fd01 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 11 Oct 2024 09:46:32 +0300 Subject: [PATCH 3/4] commons-io version update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 91789c3..b70a545 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ dependencies { testImplementation 'com.epam.reportportal:logger-java-logback:5.2.2' - testImplementation 'org.apache.commons:commons-io:1.3.2' + testImplementation 'commons-io:commons-io:2.17.0' testImplementation 'com.ibm.icu:icu4j:67.1' testImplementation ('com.google.inject:guice:5.1.0') { exclude module: 'guava' From 871735c05bea729b9a00b21582220fe7993d6e5f Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 11 Oct 2024 09:49:12 +0300 Subject: [PATCH 4/4] CHANGELOG.md update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4212f07..48a2c9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Changed - Client version updated on [5.2.15](https://github.com/reportportal/client-java/releases/tag/5.2.15), by @HardNorth - Format of last error log of test in item description was updated, by @HardNorth +### Removed +- Code reference report on Test NG's "Test" level to address issues with reruns, by @HardNorth ## [5.4.2] ### Added