-
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.
Description and item name tests and fixes
- Loading branch information
Showing
11 changed files
with
270 additions
and
59 deletions.
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
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
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
58 changes: 58 additions & 0 deletions
58
src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.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,58 @@ | ||
package com.epam.reportportal.karate.description; | ||
|
||
import com.epam.reportportal.karate.utils.TestUtils; | ||
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 org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import java.util.List; | ||
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.endsWith; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.same; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class NoDescriptionTest { | ||
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(3).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); | ||
mockBatchLogging(client); | ||
} | ||
|
||
@Test | ||
public void test_description_for_all_possible_items() { | ||
var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); | ||
assertThat(results.getFailCount(), equalTo(0)); | ||
|
||
ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(featureCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); | ||
|
||
StartTestItemRQ featureStart = featureCaptor.getValue(); | ||
assertThat(featureStart.getDescription(), endsWith("feature/simple.feature")); | ||
|
||
StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); | ||
assertThat(scenarioStart.getDescription(), nullValue()); | ||
|
||
stepCaptor.getAllValues().forEach(step -> assertThat(step.getDescription(), nullValue())); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.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,68 @@ | ||
package com.epam.reportportal.karate.description; | ||
|
||
import com.epam.reportportal.karate.utils.TestUtils; | ||
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.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.endsWith; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.same; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class SimpleDescriptionTest { | ||
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(3).collect(Collectors.toList()); | ||
private final List<Pair<String, String>> nestedStepIds = 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_description_for_all_possible_items() { | ||
var results = TestUtils.runAsReport(rp, "classpath:feature/description.feature"); | ||
assertThat(results.getFailCount(), equalTo(0)); | ||
|
||
ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(featureCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); | ||
|
||
StartTestItemRQ featureStart = featureCaptor.getValue(); | ||
assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); | ||
|
||
StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); | ||
assertThat(scenarioStart.getDescription(), equalTo("This is my Scenario description.")); | ||
|
||
List<StartTestItemRQ> backgroundSteps = stepCaptor.getAllValues().stream() | ||
.filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); | ||
assertThat(backgroundSteps, hasSize(1)); | ||
StartTestItemRQ backgroundStep = backgroundSteps.get(0); | ||
assertThat("No support of Background description in Karate yet. But this is a part of Gherkin standard.", | ||
backgroundStep.getDescription(), nullValue()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.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,65 @@ | ||
package com.epam.reportportal.karate.name; | ||
|
||
import com.epam.reportportal.karate.utils.TestUtils; | ||
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 org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
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.Mockito.*; | ||
|
||
public class SimpleItemNameTest { | ||
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(3).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); | ||
mockBatchLogging(client); | ||
} | ||
|
||
@Test | ||
public void test_scenario_code_reference() { | ||
var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); | ||
assertThat(results.getFailCount(), equalTo(0)); | ||
|
||
ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(1)).startTestItem(featureCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(1)).startTestItem(same(featureId), scenarioCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); | ||
|
||
StartTestItemRQ featureRq = featureCaptor.getValue(); | ||
StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); | ||
|
||
assertThat(featureRq.getName(), allOf(notNullValue(), equalTo("the very basic test to run by Karate"))); | ||
|
||
assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); | ||
|
||
List<StartTestItemRQ> stepRqs = stepCaptor.getAllValues(); | ||
String[] stepNames = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", | ||
"Then assert actualFour == four"}; | ||
IntStream.range(0, stepRqs.size()).forEach(i -> { | ||
StartTestItemRQ step = stepRqs.get(i); | ||
assertThat(step.getName(), allOf(notNullValue(), equalTo(stepNames[i]))); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.