-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.epam.reportportal.karate.background; | ||
|
||
import com.epam.reportportal.karate.utils.TestUtils; | ||
import com.epam.reportportal.listeners.ItemType; | ||
import com.epam.reportportal.service.ReportPortal; | ||
import com.epam.reportportal.service.ReportPortalClient; | ||
import com.epam.reportportal.util.test.CommonUtils; | ||
import com.epam.ta.reportportal.ws.model.StartTestItemRQ; | ||
import com.intuit.karate.core.Background; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static com.epam.reportportal.karate.utils.TestUtils.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.same; | ||
import static org.mockito.ArgumentMatchers.startsWith; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class BackgroundTwoStepsTest { | ||
private final String featureId = CommonUtils.namedId("feature_"); | ||
private final String scenarioId = CommonUtils.namedId("scenario_"); | ||
private final List<String> stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) | ||
.limit(2).collect(Collectors.toList()); | ||
private final List<Pair<String, String>> nestedStepIds = Stream.concat( | ||
stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))), | ||
stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_")))).collect(Collectors.toList() | ||
); | ||
|
||
private final ReportPortalClient client = mock(ReportPortalClient.class); | ||
private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); | ||
|
||
@BeforeEach | ||
public void setupMock() { | ||
mockLaunch(client, null, featureId, scenarioId, stepIds); | ||
mockNestedSteps(client, nestedStepIds); | ||
mockBatchLogging(client); | ||
} | ||
|
||
@Test | ||
public void test_background_steps() { | ||
var results = TestUtils.runAsReport(rp, "classpath:feature/background_two_steps.feature"); | ||
assertThat(results.getFailCount(), equalTo(0)); | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(captor.capture()); | ||
verify(client, times(1)).startTestItem(same(featureId), captor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); | ||
|
||
List<StartTestItemRQ> items = captor.getAllValues(); | ||
assertThat(items, hasSize(2)); | ||
List<StartTestItemRQ> steps = stepCaptor.getAllValues(); | ||
assertThat(steps, hasSize(2)); | ||
|
||
List<StartTestItemRQ> backgroundSteps = steps.stream() | ||
.filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); | ||
assertThat(backgroundSteps, hasSize(1)); | ||
StartTestItemRQ backgroundStep = backgroundSteps.get(0); | ||
assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate | ||
assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); | ||
assertThat(backgroundStep.getStartTime(), notNullValue()); | ||
assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); | ||
|
||
List<StartTestItemRQ> nestedSteps = nestedStepCaptor.getAllValues(); | ||
assertThat(nestedSteps, hasSize(2)); | ||
nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); | ||
Set<String> nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); | ||
|
||
assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: test background with two steps reporting | ||
|
||
Background: Set variable | ||
Given def vara = 2 | ||
And def varb = 2 | ||
|
||
Scenario: Verify math | ||
Then assert vara * varb == 4 |