-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from reportportal/develop
Release
- Loading branch information
Showing
12 changed files
with
314 additions
and
16 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
148 changes: 148 additions & 0 deletions
148
src/test/java/com/epam/reportportal/junit5/DescriptionTest.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,148 @@ | ||
package com.epam.reportportal.junit5; | ||
|
||
import com.epam.reportportal.junit5.features.description.*; | ||
import com.epam.reportportal.junit5.util.TestUtils; | ||
import com.epam.reportportal.service.Launch; | ||
import com.epam.reportportal.util.test.CommonUtils; | ||
import com.epam.ta.reportportal.ws.model.StartTestItemRQ; | ||
import io.reactivex.Maybe; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.stubbing.Answer; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Oleksandr Fomenko</a> | ||
*/ | ||
public class DescriptionTest { | ||
public static class TestExtension extends ReportPortalExtension { | ||
static Launch LAUNCH; | ||
|
||
@Override | ||
protected Launch getLaunch(ExtensionContext context) { | ||
return LAUNCH; | ||
} | ||
} | ||
|
||
@BeforeEach | ||
public void setupMock() { | ||
TestExtension.LAUNCH = mock(Launch.class); | ||
when(TestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid()); | ||
when(TestExtension.LAUNCH.startTestItem(any(), | ||
any() | ||
)).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid()); | ||
} | ||
|
||
@Test | ||
void descriptionFromMethodAnnotationTest() { | ||
TestUtils.runClasses(DescriptionAnnotatedMethodTest.class); | ||
|
||
Launch launch = TestExtension.LAUNCH; | ||
|
||
verify(launch, times(1)).startTestItem(any()); // Start parent Suite | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(launch, times(1)).startTestItem(notNull(), captor.capture()); // Start a test | ||
|
||
StartTestItemRQ request = captor.getValue(); | ||
assertThat(request.getDescription(), equalTo(DescriptionAnnotatedMethodTest.TEST_DESCRIPTION_METHOD)); | ||
} | ||
|
||
@Test | ||
void descriptionFromClassAnnotationTest() { | ||
TestUtils.runClasses(DescriptionAnnotatedClassTest.class); | ||
|
||
Launch launch = TestExtension.LAUNCH; | ||
|
||
verify(launch, times(1)).startTestItem(any()); // Start parent Suite | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(launch, times(1)).startTestItem(notNull(), captor.capture()); // Start a test | ||
|
||
StartTestItemRQ request = captor.getValue(); | ||
assertThat(request.getDescription(), equalTo(DescriptionAnnotatedClassTest.TEST_DESCRIPTION_CLASS)); | ||
} | ||
|
||
@Test | ||
void descriptionFromBothMethodAndClassAnnotationTest() { | ||
TestUtils.runClasses(DescriptionAnnotatedMethodAndClassTest.class); | ||
|
||
Launch launch = TestExtension.LAUNCH; | ||
|
||
verify(launch, times(1)).startTestItem(any()); // Start parent Suite | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(launch, times(1)).startTestItem(notNull(), captor.capture()); // Start a test | ||
|
||
StartTestItemRQ request = captor.getValue(); | ||
//from both annotations the expected one should be taken from the method | ||
assertThat(request.getDescription(), equalTo(DescriptionAnnotatedMethodTest.TEST_DESCRIPTION_METHOD)); | ||
} | ||
|
||
@Test | ||
void descriptionFromMethodAnnotationDynamicTest() { | ||
TestUtils.runClasses(DescriptionAnnotatedMethodDynamicTest.class); | ||
|
||
Launch launch = TestExtension.LAUNCH; | ||
verify(launch, times(1)).startTestItem(any()); // Start parent Suite | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(launch, times(2)).startTestItem(notNull(), captor.capture()); // Start a test | ||
|
||
List<String> testStepsDescription = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getDescription) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(testStepsDescription, hasItem(DescriptionAnnotatedMethodDynamicTest.TEST_DESCRIPTION_DYNAMIC_METHOD)); | ||
} | ||
|
||
@Test | ||
void descriptionFromClassAnnotationDynamicTest() { | ||
TestUtils.runClasses(DescriptionAnnotatedClassDynamicTest.class); | ||
|
||
Launch launch = TestExtension.LAUNCH; | ||
verify(launch, times(1)).startTestItem(any()); // Start parent Suite | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(launch, times(2)).startTestItem(notNull(), captor.capture()); // Start a test | ||
|
||
List<String> testStepsDescription = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getDescription) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(testStepsDescription, hasItem(DescriptionAnnotatedClassDynamicTest.TEST_DESCRIPTION_DYNAMIC_CLASS)); | ||
} | ||
|
||
@Test | ||
void descriptionFromBothMethodAndClassAnnotationDynamicTest() { | ||
TestUtils.runClasses(DescriptionAnnotatedMethodAndClassDynamicTest.class); | ||
|
||
Launch launch = TestExtension.LAUNCH; | ||
verify(launch, times(1)).startTestItem(any()); // Start parent Suite | ||
|
||
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(launch, times(2)).startTestItem(notNull(), captor.capture()); // Start a test | ||
|
||
List<String> testStepsDescription = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getDescription) | ||
.collect(Collectors.toList()); | ||
//from both annotations the expected one should be taken from the method | ||
assertThat(testStepsDescription, hasItem(DescriptionAnnotatedMethodDynamicTest.TEST_DESCRIPTION_DYNAMIC_METHOD)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...m/epam/reportportal/junit5/features/description/DescriptionAnnotatedClassDynamicTest.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,22 @@ | ||
package com.epam.reportportal.junit5.features.description; | ||
|
||
import com.epam.reportportal.annotations.Description; | ||
import com.epam.reportportal.junit5.DescriptionTest; | ||
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(DescriptionTest.TestExtension.class) | ||
@Description(DescriptionAnnotatedClassDynamicTest.TEST_DESCRIPTION_DYNAMIC_CLASS) | ||
public class DescriptionAnnotatedClassDynamicTest { | ||
public static final String TEST_DESCRIPTION_DYNAMIC_CLASS = "My test description on the dynamic class"; | ||
@TestFactory | ||
|
||
Stream<DynamicTest> testForTestFactory() { | ||
return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...java/com/epam/reportportal/junit5/features/description/DescriptionAnnotatedClassTest.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,15 @@ | ||
package com.epam.reportportal.junit5.features.description; | ||
|
||
import com.epam.reportportal.annotations.Description; | ||
import com.epam.reportportal.junit5.DescriptionTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@Description(DescriptionAnnotatedClassTest.TEST_DESCRIPTION_CLASS) | ||
@ExtendWith(DescriptionTest.TestExtension.class) | ||
public class DescriptionAnnotatedClassTest { | ||
public static final String TEST_DESCRIPTION_CLASS = "My test description on the class"; | ||
@Test | ||
public void testDescriptionTest() { | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...portportal/junit5/features/description/DescriptionAnnotatedMethodAndClassDynamicTest.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,21 @@ | ||
package com.epam.reportportal.junit5.features.description; | ||
|
||
import com.epam.reportportal.annotations.Description; | ||
import com.epam.reportportal.junit5.DescriptionTest; | ||
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(DescriptionTest.TestExtension.class) | ||
@Description(DescriptionAnnotatedClassDynamicTest.TEST_DESCRIPTION_DYNAMIC_CLASS) | ||
public class DescriptionAnnotatedMethodAndClassDynamicTest { | ||
@TestFactory | ||
@Description(DescriptionAnnotatedMethodDynamicTest.TEST_DESCRIPTION_DYNAMIC_METHOD) | ||
Stream<DynamicTest> testForTestFactory() { | ||
return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); | ||
} | ||
} |
Oops, something went wrong.