diff --git a/src/test/java/com/epam/reportportal/junit5/BasicTest.java b/src/test/java/com/epam/reportportal/junit5/BasicTest.java index b201217..a803465 100644 --- a/src/test/java/com/epam/reportportal/junit5/BasicTest.java +++ b/src/test/java/com/epam/reportportal/junit5/BasicTest.java @@ -16,7 +16,7 @@ package com.epam.reportportal.junit5; -import com.epam.reportportal.junit5.features.basic.TestFailure; +import com.epam.reportportal.junit5.features.TestFailure; import com.epam.reportportal.junit5.util.TestUtils; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.service.Launch; diff --git a/src/test/java/com/epam/reportportal/junit5/IssueReportingTest.java b/src/test/java/com/epam/reportportal/junit5/IssueReportingTest.java new file mode 100644 index 0000000..9412a79 --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/IssueReportingTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2024 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 + * + * https://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.junit5; + +import com.epam.reportportal.junit5.features.issue.SimpleIssueTest; +import com.epam.reportportal.junit5.util.TestUtils; +import com.epam.reportportal.listeners.ItemStatus; +import com.epam.reportportal.service.Launch; +import com.epam.reportportal.util.test.CommonUtils; +import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import com.epam.ta.reportportal.ws.model.OperationCompletionRS; +import com.epam.ta.reportportal.ws.model.issue.Issue; +import io.reactivex.Maybe; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.mockito.ArgumentCaptor; +import org.mockito.stubbing.Answer; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class IssueReportingTest { + public static class TestExtension extends ReportPortalExtension { + static Launch LAUNCH; + + @Override + protected Launch getLaunch(ExtensionContext context) { + return LAUNCH; + } + } + + private final String SUITE_ID = CommonUtils.namedId("suite_"); + private final Maybe SUITE_MAYBE = Maybe.just(SUITE_ID); + private final String STEP_ID = CommonUtils.namedId("step_"); + private final Maybe STEP_MAYBE = Maybe.just(STEP_ID); + + @BeforeEach + public void setupMock() { + Launch launch = mock(Launch.class); + IssueReportingTest.TestExtension.LAUNCH = launch; + when(launch.startTestItem(any())).thenAnswer((Answer>) invocation -> SUITE_MAYBE); + when(launch.startTestItem(same(SUITE_MAYBE), any())).thenAnswer((Answer>) invocation -> STEP_MAYBE); + when(launch.finishTestItem(any(), + any() + )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS("OK"))); + } + + @Test + public void verify_simple_test_failure() { + TestUtils.runClasses(SimpleIssueTest.class); + + Launch launch = IssueReportingTest.TestExtension.LAUNCH; + ArgumentCaptor testCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(launch).finishTestItem(same(STEP_MAYBE), testCaptor.capture()); + + FinishTestItemRQ finishTestItemRQ = testCaptor.getValue(); + assertThat(finishTestItemRQ.getStatus(), equalTo(ItemStatus.FAILED.name())); + assertThat(finishTestItemRQ.getIssue(), notNullValue()); + Issue issue = finishTestItemRQ.getIssue(); + assertThat(issue.getIssueType(), equalTo("pb001")); + assertThat(issue.getComment(), equalTo(SimpleIssueTest.FAILURE_MESSAGE)); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/basic/TestFailure.java b/src/test/java/com/epam/reportportal/junit5/features/TestFailure.java similarity index 87% rename from src/test/java/com/epam/reportportal/junit5/features/basic/TestFailure.java rename to src/test/java/com/epam/reportportal/junit5/features/TestFailure.java index 159ba85..31159aa 100644 --- a/src/test/java/com/epam/reportportal/junit5/features/basic/TestFailure.java +++ b/src/test/java/com/epam/reportportal/junit5/features/TestFailure.java @@ -1,11 +1,11 @@ /* - * Copyright 2022 EPAM Systems + * Copyright 2024 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 + * https://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, @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.epam.reportportal.junit5.features.basic; +package com.epam.reportportal.junit5.features; import com.epam.reportportal.junit5.BasicTest; import org.junit.jupiter.api.Assertions; diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/DynamicIssueTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/DynamicIssueTest.java new file mode 100644 index 0000000..1ba9688 --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/DynamicIssueTest.java @@ -0,0 +1,24 @@ +package com.epam.reportportal.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import com.epam.reportportal.junit5.DisplayNameTest; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.DynamicTest.dynamicTest; + +@ExtendWith(DisplayNameTest.TestExtension.class) +public class DynamicIssueTest { + public static final String FAILURE_MESSAGE = "This test is expected to fail"; + + @TestFactory + @Issue(value = "ab001", comment = FAILURE_MESSAGE) + Stream testForTestFactory() { + return Stream.of(dynamicTest("My dynamic test", () -> { + throw new IllegalStateException(FAILURE_MESSAGE); + })); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithOneIssueTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithOneIssueTest.java new file mode 100644 index 0000000..e345dac --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithOneIssueTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2024 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 + * + * https://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.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import com.epam.reportportal.annotations.TestFilter; +import com.epam.reportportal.annotations.TestParamFilter; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@ExtendWith(com.epam.reportportal.junit5.ReportPortalExtension.class) +public class ParameterizedWithOneIssueTest { + + public static final String FAILURE_MESSAGE = "This parameterized test is expected to fail: "; + + @ParameterizedTest + @ValueSource(booleans = { true, false }) + @Issue(value = "ab001", comment = "This test is expected to fail", filter = @TestFilter(param = { + @TestParamFilter(valueStartsWith = "true") })) + public void failureTest(boolean param) { + throw new IllegalStateException(FAILURE_MESSAGE + param); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithTwoIssueTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithTwoIssueTest.java new file mode 100644 index 0000000..c368b8e --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/ParameterizedWithTwoIssueTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2024 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 + * + * https://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.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import com.epam.reportportal.annotations.TestFilter; +import com.epam.reportportal.annotations.TestParamFilter; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@ExtendWith(com.epam.reportportal.junit5.ReportPortalExtension.class) +public class ParameterizedWithTwoIssueTest { + + public static final String FAILURE_MESSAGE = "This parameterized test is expected to fail: "; + public static final String ISSUE_MESSAGE = "This test is expected to fail"; + + @ParameterizedTest + @ValueSource(booleans = { true, false }) + @Issue(value = "ab001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "true") })) + @Issue(value = "pb001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "false") })) + public void failureTest(boolean param) { + throw new IllegalStateException(FAILURE_MESSAGE + param); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/SimpleIssueTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/SimpleIssueTest.java new file mode 100644 index 0000000..6b754be --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/SimpleIssueTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 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 + * + * https://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.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import com.epam.reportportal.junit5.IssueReportingTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(IssueReportingTest.TestExtension.class) +public class SimpleIssueTest { + + public static final String FAILURE_MESSAGE = "This test is expected to fail"; + + @Test + @Issue(value = "pb001", comment = FAILURE_MESSAGE) + public void failureTest() { + throw new IllegalStateException(FAILURE_MESSAGE); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/SimpleTwoIssuesTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/SimpleTwoIssuesTest.java new file mode 100644 index 0000000..1714ed1 --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/SimpleTwoIssuesTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 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 + * + * https://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.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(com.epam.reportportal.junit5.ReportPortalExtension.class) +public class SimpleTwoIssuesTest { + + public static final String FAILURE_MESSAGE = "This test is expected to fail"; + + @Test + @Issue(value = "pb001", comment = FAILURE_MESSAGE) + @Issue(value = "ab001", comment = FAILURE_MESSAGE) + public void failureTest() { + throw new IllegalStateException(FAILURE_MESSAGE); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicIssueTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicIssueTest.java new file mode 100644 index 0000000..e9322a7 --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicIssueTest.java @@ -0,0 +1,26 @@ +package com.epam.reportportal.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import com.epam.reportportal.junit5.DisplayNameTest; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.DynamicTest.dynamicTest; + +@ExtendWith(DisplayNameTest.TestExtension.class) +public class TwoDynamicIssueTest { + public static final String FAILURE_MESSAGE = "This test is expected to fail"; + + @TestFactory + @Issue(value = "ab001", comment = FAILURE_MESSAGE) + Stream testForTestFactory() { + return Stream.of(dynamicTest("My dynamic test", () -> { + throw new IllegalStateException(FAILURE_MESSAGE); + }), dynamicTest("My dynamic test 2", () -> { + throw new IllegalStateException(FAILURE_MESSAGE); + })); + } +} diff --git a/src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicTwoIssueTest.java b/src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicTwoIssueTest.java new file mode 100644 index 0000000..8667c0b --- /dev/null +++ b/src/test/java/com/epam/reportportal/junit5/features/issue/TwoDynamicTwoIssueTest.java @@ -0,0 +1,29 @@ +package com.epam.reportportal.junit5.features.issue; + +import com.epam.reportportal.annotations.Issue; +import com.epam.reportportal.annotations.TestFilter; +import com.epam.reportportal.annotations.TestNameFilter; +import com.epam.reportportal.junit5.DisplayNameTest; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.DynamicTest.dynamicTest; + +@ExtendWith(DisplayNameTest.TestExtension.class) +public class TwoDynamicTwoIssueTest { + public static final String FAILURE_MESSAGE = "This test is expected to fail"; + + @TestFactory + @Issue(value = "ab001", comment = FAILURE_MESSAGE, filter = {@TestFilter(name = @TestNameFilter(endsWith = "test")) }) + @Issue(value = "pb001", comment = FAILURE_MESSAGE, filter = {@TestFilter(name = @TestNameFilter(contains = "test 2")) }) + Stream testForTestFactory() { + return Stream.of(dynamicTest("My dynamic test", () -> { + throw new IllegalStateException(FAILURE_MESSAGE); + }), dynamicTest("My dynamic test 2", () -> { + throw new IllegalStateException(FAILURE_MESSAGE); + })); + } +}