-
Notifications
You must be signed in to change notification settings - Fork 17
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
7 changed files
with
258 additions
and
30 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
71 changes: 71 additions & 0 deletions
71
src/test/java/com/epam/reportportal/junit/features/skip/ParameterizedIgnoredTest.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,71 @@ | ||
/* | ||
* Copyright 2020 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.junit.features.skip; | ||
|
||
import com.epam.reportportal.annotations.ParameterKey; | ||
import com.google.common.base.Optional; | ||
import com.nordstrom.automation.junit.ArtifactParams; | ||
import com.nordstrom.automation.junit.AtomIdentity; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ParameterizedIgnoredTest implements ArtifactParams { | ||
|
||
@Rule | ||
public final AtomIdentity identity = new AtomIdentity(this); | ||
|
||
@Parameters | ||
public static Object[] params() { | ||
return new Object[] { "one", "two, three" }; | ||
} | ||
|
||
private final String parameter; | ||
|
||
public ParameterizedIgnoredTest(@ParameterKey("param") String param) { | ||
parameter = param; | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void testParameters() { | ||
System.out.println("Parameter test: " + parameter); | ||
} | ||
|
||
@Override | ||
public AtomIdentity getAtomIdentity() { | ||
return identity; | ||
} | ||
|
||
@Override | ||
public Description getDescription() { | ||
return identity.getDescription(); | ||
} | ||
|
||
@Override | ||
public Optional<Map<String, Object>> getParameters() { | ||
return Optional.of(Collections.singletonMap("param", parameter)); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/test/java/com/epam/reportportal/junit/ignore/BasicIgnoreTest.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 @@ | ||
/* | ||
* Copyright 2020 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.junit.ignore; | ||
|
||
import com.epam.reportportal.junit.ParallelRunningHandler; | ||
import com.epam.reportportal.junit.features.skip.IgnoredTest; | ||
import com.epam.reportportal.junit.utils.TestUtils; | ||
import com.epam.reportportal.listeners.ItemStatus; | ||
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.FinishTestItemRQ; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.same; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class BasicIgnoreTest { | ||
|
||
private final String launchId = CommonUtils.namedId("launch_"); | ||
private final String suiteId = CommonUtils.namedId("suite_"); | ||
private final String classId = CommonUtils.namedId("class_"); | ||
private final String methodId = CommonUtils.namedId("method_"); | ||
|
||
private final ReportPortalClient client = mock(ReportPortalClient.class); | ||
|
||
@BeforeEach | ||
public void setupMock() { | ||
TestUtils.mockLaunch(client, launchId, suiteId, classId, methodId); | ||
TestUtils.mockLogging(client); | ||
ParallelRunningHandler.setReportPortal(ReportPortal.create(client, TestUtils.standardParameters())); | ||
} | ||
|
||
@Test | ||
public void verify_an_ignored_test_reporting() { | ||
TestUtils.runClasses(IgnoredTest.class); | ||
|
||
verify(client, times(1)).startTestItem(any()); | ||
verify(client, times(1)).startTestItem(same(suiteId), any()); | ||
ArgumentCaptor<FinishTestItemRQ> finishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); | ||
verify(client, times(1)).startTestItem(same(classId), any()); | ||
verify(client, times(1)).finishTestItem(same(methodId), finishCaptor.capture()); | ||
|
||
FinishTestItemRQ finishRq = finishCaptor.getValue(); | ||
|
||
assertThat(finishRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.SKIPPED.name()))); | ||
assertThat(finishRq.getIssue(), nullValue()); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/test/java/com/epam/reportportal/junit/ignore/IgnoreParameterizedTest.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 @@ | ||
/* | ||
* Copyright 2020 EPAM Systems | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.epam.reportportal.junit.ignore; | ||
|
||
import com.epam.reportportal.junit.ParallelRunningHandler; | ||
import com.epam.reportportal.junit.features.skip.ParameterizedIgnoredTest; | ||
import com.epam.reportportal.junit.utils.TestUtils; | ||
import com.epam.reportportal.listeners.ItemStatus; | ||
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.FinishTestItemRQ; | ||
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 org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class IgnoreParameterizedTest { | ||
|
||
private final String launchId = CommonUtils.namedId("launch_"); | ||
private final String suiteId = CommonUtils.namedId("suite_"); | ||
private final String classId = CommonUtils.namedId("class_"); | ||
private final List<String> methodIds = Stream.generate(() -> CommonUtils.namedId("method_")).limit(2).collect(Collectors.toList()); | ||
|
||
private final ReportPortalClient client = mock(ReportPortalClient.class); | ||
|
||
@BeforeEach | ||
public void setupMock() { | ||
TestUtils.mockLaunch(client, launchId, suiteId, classId, methodIds); | ||
TestUtils.mockLogging(client); | ||
ParallelRunningHandler.setReportPortal(ReportPortal.create(client, TestUtils.standardParameters())); | ||
} | ||
|
||
@Test | ||
public void verify_a_test_with_one_retry() { | ||
TestUtils.runClasses(ParameterizedIgnoredTest.class); | ||
|
||
verify(client, times(1)).startTestItem(any()); | ||
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
ArgumentCaptor<FinishTestItemRQ> finishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); | ||
verify(client, times(1)).startTestItem(same(suiteId), any()); | ||
verify(client, times(2)).startTestItem(same(classId), startCaptor.capture()); | ||
verify(client, times(1)).finishTestItem(same(methodIds.get(0)), finishCaptor.capture()); | ||
verify(client, times(1)).finishTestItem(same(methodIds.get(1)), finishCaptor.capture()); | ||
|
||
List<StartTestItemRQ> startRqs = startCaptor.getAllValues(); | ||
assertThat(startRqs.get(0).getTestCaseId(), not(equalTo(startRqs.get(1).getTestCaseId()))); // test case ID should be parameterized | ||
assertThat(startRqs.get(0).getParameters(), allOf(notNullValue(), hasSize(1))); | ||
assertThat(startRqs.get(1).getParameters(), allOf(notNullValue(), hasSize(1))); | ||
assertThat(startRqs.get(0).getCodeRef(), equalTo(startRqs.get(1).getCodeRef())); | ||
|
||
finishCaptor.getAllValues().forEach(i -> { | ||
assertThat(i.getIssue(), nullValue()); | ||
assertThat(i.getStatus(), equalTo(ItemStatus.SKIPPED.name())); | ||
}); | ||
} | ||
|
||
} |
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