Skip to content

Commit

Permalink
Merge pull request #211 from reportportal/EPMRPP-93199_fix_rerun
Browse files Browse the repository at this point in the history
[EPMRPP-93199] fix rerun
  • Loading branch information
HardNorth authored Oct 11, 2024
2 parents f9788d1 + 871735c commit 2ff0b82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## [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
### Removed
- Code reference report on Test NG's "Test" level to address issues with reruns, by @HardNorth

## [5.4.2]
### Added
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
43 changes: 21 additions & 22 deletions src/main/java/com/epam/reportportal/testng/TestNGService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,14 @@
* TestNG service implements operations for interaction ReportPortal
*/
public class TestNGService implements ITestNGService {
private static final Set<TestMethodType> BEFORE_METHODS = Stream.of(
TestMethodType.BEFORE_TEST,
private static final Set<TestMethodType> 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<String> TESTNG_INVOKERS = Stream.of(
"org.testng.internal.TestInvoker",
private static final Set<String> TESTNG_INVOKERS = Stream.of("org.testng.internal.TestInvoker",
"org.testng.internal.invokers.TestInvoker"
).collect(Collectors.toSet());
private static final Predicate<StackTraceElement> IS_RETRY_ELEMENT = e -> TESTNG_INVOKERS.contains(e.getClassName())
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -533,13 +529,9 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull ITestContext testContext
StartTestItemRQ rq = new StartTestItemRQ();
Set<ItemAttributesRQ> 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");
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -747,8 +739,13 @@ private TestCaseIdEntry getTestCaseId(@Nonnull String codeRef, @Nonnull ITestRes
List<Object> 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;
}
Expand Down Expand Up @@ -807,12 +804,14 @@ Maybe<String> 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);
}
}

0 comments on commit 2ff0b82

Please sign in to comment.