Skip to content

Commit

Permalink
Merge pull request #128 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Apr 9, 2024
2 parents 45867c9 + 33466bb commit 1998553
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
java-version: '8'

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
name: 'reportportal.io'
email: 'support@reportportal.io'
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.2.14](https://github.com/reportportal/client-java/releases/tag/5.2.14), by @HardNorth
- Do not hide test description when test is disabled with reason, by @HardNorth

## [5.3.1]
### Added
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repositories {
}

dependencies {
api 'com.epam.reportportal:client-java:5.2.13'
api 'com.epam.reportportal:client-java:5.2.14'

compileOnly "org.junit.jupiter:junit-jupiter-api:${junit_version}"
implementation 'org.slf4j:slf4j-api:2.0.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.epam.reportportal.utils.AttributeParser;
import com.epam.reportportal.utils.ParameterUtils;
import com.epam.reportportal.utils.TestCaseIdUtils;
import com.epam.reportportal.utils.markdown.MarkdownUtils;
import com.epam.ta.reportportal.ws.model.*;
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
Expand Down Expand Up @@ -352,8 +353,11 @@ public void afterTestExecution(ExtensionContext context) {
public void testDisabled(ExtensionContext context, Optional<String> reason) {
if (Boolean.parseBoolean(System.getProperty("reportDisabledTests"))) {
final ItemType itemType = STEP;
String description = reason.orElse(createStepDescription(context, itemType));
startTestItem(context, Collections.emptyList(), itemType, description, Calendar.getInstance().getTime());
String description = reason.map(r -> {
String rawDescription = createStepDescription(context, itemType);
return StringUtils.isNotBlank(rawDescription) ? MarkdownUtils.asTwoParts(r, rawDescription) : r;
}).orElse(null);
startTestItem(context, Collections.emptyList(), itemType, description, null);
finishTest(context, SKIPPED);
}
}
Expand Down Expand Up @@ -457,7 +461,7 @@ protected void startTestItem(ExtensionContext context, ItemType type) {
* @param type a type of the item
*/
protected void startTestItem(ExtensionContext context, List<Object> arguments, ItemType type) {
startTestItem(context, arguments, type, createStepDescription(context, type), Calendar.getInstance().getTime());
startTestItem(context, arguments, type, null, null);
}

/**
Expand All @@ -466,11 +470,9 @@ protected void startTestItem(ExtensionContext context, List<Object> arguments, I
* @param context JUnit's test context
* @param arguments a list of test parameters
* @param itemType a type of the item
* @param description the test description
* @param startTime the test start time
*/
protected void startTestItem(@Nonnull final ExtensionContext context, @Nonnull final List<Object> arguments,
@Nonnull final ItemType itemType, @Nonnull final String description, @Nonnull final Date startTime) {
@Nonnull final ItemType itemType, @Nullable final String description, @Nullable final Date startTime) {
idMapping.computeIfAbsent(context, c -> {
StartTestItemRQ rq = buildStartStepRq(c, arguments, itemType, description, startTime);
Launch launch = getLaunch(c);
Expand Down Expand Up @@ -665,18 +667,17 @@ protected Optional<Method> getTestMethod(ExtensionContext context) {
* @param context JUnit's test context
* @param arguments a test arguments list
* @param itemType a test method item type
* @param description a test method description
* @param startTime a start time of the test
* @return Request to ReportPortal
*/
@Nonnull
protected StartTestItemRQ buildStartStepRq(@Nonnull final ExtensionContext context,
@Nonnull final List<Object> arguments, @Nonnull final ItemType itemType, @Nonnull final String description,
@Nonnull final Date startTime) {
@Nonnull final List<Object> arguments, @Nonnull final ItemType itemType, @Nullable final String description,
@Nullable final Date startTime) {
StartTestItemRQ rq = new StartTestItemRQ();
rq.setStartTime(startTime);
rq.setStartTime(ofNullable(startTime).orElseGet(Calendar.getInstance()::getTime));
rq.setName(createStepName(context));
rq.setDescription(description);
rq.setDescription(ofNullable(description).orElseGet(() -> createStepDescription(context, itemType)));
rq.setType(itemType == TEMPLATE ? SUITE.name() : itemType.name());
String codeRef = getCodeRef(context);
rq.setCodeRef(codeRef);
Expand Down Expand Up @@ -823,7 +824,7 @@ protected String createConfigurationName(@Nonnull Class<?> testClass, @Nonnull M
* @param context JUnit's test context
* @return Test/Step Description being sent to ReportPortal
*/
@SuppressWarnings("unused")
@Nonnull
protected String createStepDescription(ExtensionContext context, final ItemType itemType) {
String defaultValue = "";
if (itemType != STEP) {
Expand Down
27 changes: 23 additions & 4 deletions src/test/java/com/epam/reportportal/junit5/DisabledTestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.epam.reportportal.junit5.features.disabled.OneDisabledOneEnabledTest;
import com.epam.reportportal.junit5.features.disabled.OneDisabledTest;
import com.epam.reportportal.junit5.features.disabled.OneDisabledTestWithReason;
import com.epam.reportportal.junit5.features.disabled.OneDisabledWithReasonTest;
import com.epam.reportportal.junit5.features.disabled.OneDisabledWithReasonDescriptionTest;
import com.epam.reportportal.junit5.util.TestUtils;
import com.epam.reportportal.listeners.ItemStatus;
import com.epam.reportportal.service.Launch;
import com.epam.reportportal.service.step.StepReporter;
import com.epam.reportportal.util.test.CommonUtils;
import com.epam.reportportal.utils.markdown.MarkdownUtils;
import com.epam.ta.reportportal.ws.model.FinishTestItemRQ;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import io.reactivex.Maybe;
Expand Down Expand Up @@ -82,7 +84,7 @@ public void verify_a_disabled_test_reported_as_skipped() {

@Test
public void verify_a_disabled_test_reason_reported() {
TestUtils.runClasses(OneDisabledTestWithReason.class);
TestUtils.runClasses(OneDisabledWithReasonTest.class);

Launch launch = DisabledTestExtension.LAUNCH;

Expand All @@ -92,8 +94,8 @@ public void verify_a_disabled_test_reason_reported() {

List<StartTestItemRQ> steps = captorStart.getAllValues();
assertThat("StartTestItem request has proper Description field",
captorStart.getAllValues().get(0).getDescription(),
equalTo(OneDisabledTestWithReason.REASON)
steps.get(0).getDescription(),
equalTo(OneDisabledWithReasonTest.REASON)
);
}

Expand Down Expand Up @@ -127,6 +129,23 @@ public void verify_a_disabled_test_does_not_affect_enabled_in_the_same_class() {
assertThat("Enabled has passed status", finishStep.getStatus(), equalTo(ItemStatus.PASSED.name()));
}

@Test
public void verify_a_disabled_test_reason_and_description_reported() {
TestUtils.runClasses(OneDisabledWithReasonDescriptionTest.class);

Launch launch = DisabledTestExtension.LAUNCH;

verify(launch, times(1)).startTestItem(any()); // Start parent Suite
ArgumentCaptor<StartTestItemRQ> captorStart = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(launch, times(1)).startTestItem(notNull(), captorStart.capture()); // Start a test

List<StartTestItemRQ> steps = captorStart.getAllValues();
assertThat("StartTestItem request has proper Description field",
steps.get(0).getDescription(),
equalTo(MarkdownUtils.asTwoParts(OneDisabledWithReasonDescriptionTest.REASON, OneDisabledWithReasonDescriptionTest.TEST_DESCRIPTION_METHOD))
);
}

@AfterAll
public void cleanProperty() {
System.clearProperty("reportDisabledTests");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.epam.reportportal.junit5.features.disabled;

import com.epam.reportportal.annotations.Description;
import com.epam.reportportal.junit5.DisabledTestTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(DisabledTestTest.DisabledTestExtension.class)
public class OneDisabledWithReasonDescriptionTest {
public static final String TEST_DESCRIPTION_METHOD = "My test description on the method";
public static final String REASON = "My reason to disable test";

@Disabled(REASON)
@Description(TEST_DESCRIPTION_METHOD)
@Test
void disabledTest() {
System.out.println("disabled");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(DisabledTestTest.DisabledTestExtension.class)
public class OneDisabledTestWithReason {
public class OneDisabledWithReasonTest {

public static final String REASON = "My reason to disable test";

Expand Down

0 comments on commit 1998553

Please sign in to comment.