-
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 #130 from nick130589/feature/displayname
Added support @DisplayName annotation
- Loading branch information
Showing
16 changed files
with
563 additions
and
3 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
281 changes: 281 additions & 0 deletions
281
src/test/java/com/epam/reportportal/junit5/DisplayNameTest.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,281 @@ | ||
package com.epam.reportportal.junit5; | ||
|
||
import com.epam.reportportal.junit5.features.displayname.*; | ||
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]">Mykola Zakapko</a> | ||
*/ | ||
public class DisplayNameTest { | ||
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 displayNameFromMethodAnnotationTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedClassTest.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.getName(), equalTo(DisplayNameAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS)); | ||
} | ||
|
||
@Test | ||
void displayNameFromClassAnnotationTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedClassTest.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.getName(), equalTo(DisplayNameAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS)); | ||
} | ||
|
||
@Test | ||
void displayNameFromBothMethodAndClassAnnotationTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedMethodAndClassTest.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.getName(), equalTo(DisplayNameAnnotatedMethodTest.TEST_DISPLAY_NAME_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameFromMethodAnnotationDynamicTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedMethodDynamicTest.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> testStepsDisplayName = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getName) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(testStepsDisplayName, hasItem(DisplayNameAnnotatedMethodDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameFromClassAnnotationDynamicTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedClassDynamicTest.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> testStepsDisplayName = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getName) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(testStepsDisplayName, hasItem(DisplayNameAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS)); | ||
} | ||
|
||
@Test | ||
void displayNameFromBothMethodAndClassAnnotationDynamicTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedMethodAndClassDynamicTest.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> testStepsDisplayName = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getName) | ||
.collect(Collectors.toList()); | ||
//from both annotations the expected one should be taken from the method | ||
assertThat(testStepsDisplayName, hasItem(DisplayNameAnnotatedMethodDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameJunitAndRPFromMethodAnnotationTest() { | ||
TestUtils.runClasses(DisplayNameBothJunitAndRPAnnotatedMethodTest.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.getName(), equalTo(DisplayNameBothJunitAndRPAnnotatedMethodTest.TEST_DISPLAY_NAME_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameJunitAndRPFromClassAnnotationAnnotationTest() { | ||
TestUtils.runClasses(DisplayNameBothJunitAndRPAnnotatedClassTest.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.getName(), equalTo(DisplayNameBothJunitAndRPAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS)); | ||
} | ||
|
||
@Test | ||
void displayNameJunitAndRPFromMethodAnnotationDynamicTest() { | ||
TestUtils.runClasses(DisplayNameBothJunitAndRPAnnotatedMethodDynamicTest.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> testStepsDisplayName = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getName) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(testStepsDisplayName, hasItem(DisplayNameBothJunitAndRPAnnotatedMethodDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameJunitAndRPFromClassAnnotationDynamicTest() { | ||
TestUtils.runClasses(DisplayNameBothJunitAndRPAnnotatedClassDynamicTest.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> testStepsDisplayName = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getName) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(testStepsDisplayName, hasItem(DisplayNameBothJunitAndRPAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS)); | ||
} | ||
|
||
@Test | ||
void displayNameJunitAndRPFromBothMethodAndClassAnnotationTest() { | ||
TestUtils.runClasses(DisplayNameBothJunitAndRPAnnotatedMethodAndClassTest.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.getName(), equalTo(DisplayNameAnnotatedMethodTest.TEST_DISPLAY_NAME_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameJunitAndRPFromBothMethodAndClassAnnotationDynamicTest() { | ||
TestUtils.runClasses(DisplayNameBothJunitAndRPAnnotatedMethodAndClassDynamicTest.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> testStepsDisplayName = captor.getAllValues() | ||
.stream() | ||
.filter(e -> e.getType().equals(ItemType.STEP.name())) | ||
.map(StartTestItemRQ::getName) | ||
.collect(Collectors.toList()); | ||
//from both annotations the expected one should be taken from the method | ||
assertThat(testStepsDisplayName, hasItem(DisplayNameAnnotatedMethodDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_METHOD)); | ||
} | ||
|
||
@Test | ||
void displayNameFromClassAnnotationWithEmptyValueTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedClassWithEmptyValueTest.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.getName(), equalTo(DisplayNameAnnotatedClassWithEmptyValueTest.TEST_DISPLAY_NAME_CLASS)); | ||
} | ||
|
||
@Test | ||
void displayNameFromMethodAnnotationWithEmptyValueTest() { | ||
TestUtils.runClasses(DisplayNameAnnotatedMethodWithEmptyValueTest.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.getName(), equalTo(DisplayNameAnnotatedMethodWithEmptyValueTest.TEST_DISPLAY_NAME_METHOD)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...m/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedClassDynamicTest.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.displayname; | ||
|
||
import com.epam.reportportal.annotations.DisplayName; | ||
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) | ||
@DisplayName(DisplayNameAnnotatedClassDynamicTest.TEST_DISPLAY_NAME_DYNAMIC_CLASS) | ||
public class DisplayNameAnnotatedClassDynamicTest { | ||
public static final String TEST_DISPLAY_NAME_DYNAMIC_CLASS = "My test displayName on the dynamic class"; | ||
@TestFactory | ||
Stream<DynamicTest> testForTestFactory() { | ||
return Stream.of(dynamicTest("My dynamic test", () -> System.out.println("Inside dynamic test"))); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...java/com/epam/reportportal/junit5/features/displayname/DisplayNameAnnotatedClassTest.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,14 @@ | ||
package com.epam.reportportal.junit5.features.displayname; | ||
|
||
import com.epam.reportportal.junit5.DisplayNameTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@com.epam.reportportal.annotations.DisplayName(DisplayNameAnnotatedClassTest.TEST_DISPLAY_NAME_CLASS) | ||
@ExtendWith(DisplayNameTest.TestExtension.class) | ||
public class DisplayNameAnnotatedClassTest { | ||
public static final String TEST_DISPLAY_NAME_CLASS = "My display name"; | ||
@Test | ||
public void testDisplayNameTest() { | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...reportportal/junit5/features/displayname/DisplayNameAnnotatedClassWithEmptyValueTest.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,14 @@ | ||
package com.epam.reportportal.junit5.features.displayname; | ||
|
||
import com.epam.reportportal.junit5.DisplayNameTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@com.epam.reportportal.annotations.DisplayName(DisplayNameAnnotatedClassWithEmptyValueTest.TEST_DISPLAY_NAME_CLASS) | ||
@ExtendWith(DisplayNameTest.TestExtension.class) | ||
public class DisplayNameAnnotatedClassWithEmptyValueTest { | ||
public static final String TEST_DISPLAY_NAME_CLASS = ""; | ||
@Test | ||
public void testDisplayNameTest() { | ||
} | ||
} |
Oops, something went wrong.