|
61 | 61 | import org.spockframework.runtime.GlobalExtensionRegistry; |
62 | 62 | import org.spockframework.runtime.RunContext; |
63 | 63 | import org.spockframework.runtime.SpockEngine; |
| 64 | +import org.mockito.ArgumentCaptor; |
64 | 65 |
|
| 66 | +import java.lang.reflect.Method; |
65 | 67 | import java.time.Instant; |
66 | 68 | import java.util.Arrays; |
67 | 69 | import java.util.Collection; |
|
73 | 75 |
|
74 | 76 | import static org.assertj.core.api.Assertions.assertThat; |
75 | 77 | import static org.assertj.core.api.Assertions.tuple; |
| 78 | +import static org.mockito.Mockito.mock; |
| 79 | +import static org.mockito.Mockito.times; |
| 80 | +import static org.mockito.Mockito.verify; |
| 81 | +import static org.mockito.Mockito.verifyNoInteractions; |
| 82 | +import static org.mockito.Mockito.when; |
76 | 83 |
|
77 | 84 | /** |
78 | 85 | * @author charlie (Dmitry Baev). |
79 | 86 | */ |
80 | 87 | class AllureSpock2Test { |
81 | 88 |
|
| 89 | + @Test |
| 90 | + void shouldCreateNewUuidForEachIteration() throws Exception { |
| 91 | + final io.qameta.allure.AllureLifecycle lifecycle = mock(io.qameta.allure.AllureLifecycle.class); |
| 92 | + final AllureSpock2 allureSpock2 = new AllureSpock2(lifecycle); |
| 93 | + |
| 94 | + final org.spockframework.runtime.model.SpecInfo specInfo = mock(org.spockframework.runtime.model.SpecInfo.class); |
| 95 | + final org.spockframework.runtime.model.FeatureInfo featureInfo = mock(org.spockframework.runtime.model.FeatureInfo.class); |
| 96 | + final org.spockframework.runtime.model.MethodInfo methodInfo = mock(org.spockframework.runtime.model.MethodInfo.class); |
| 97 | + final org.spockframework.runtime.model.IterationInfo iterationInfo = mock(org.spockframework.runtime.model.IterationInfo.class); |
| 98 | + |
| 99 | + final Method method = DummySpec.class.getMethod("dummy"); |
| 100 | + when(methodInfo.getReflection()).thenReturn(method); |
| 101 | + |
| 102 | + when(specInfo.getReflection()).thenReturn((Class) DummySpec.class); |
| 103 | + when(specInfo.getPackage()).thenReturn(DummySpec.class.getPackage().getName()); |
| 104 | + when(specInfo.getName()).thenReturn(DummySpec.class.getSimpleName()); |
| 105 | + when(specInfo.getSubSpec()).thenReturn(null); |
| 106 | + when(specInfo.getSuperSpec()).thenReturn(null); |
| 107 | + |
| 108 | + when(featureInfo.getFeatureMethod()).thenReturn(methodInfo); |
| 109 | + when(featureInfo.getSpec()).thenReturn(specInfo); |
| 110 | + when(featureInfo.getDataVariables()).thenReturn(Collections.emptyList()); |
| 111 | + when(featureInfo.getTestTags()).thenReturn(Collections.emptySet()); |
| 112 | + |
| 113 | + when(iterationInfo.getFeature()).thenReturn(featureInfo); |
| 114 | + when(iterationInfo.getDataValues()).thenReturn(new Object[0]); |
| 115 | + when(iterationInfo.getDisplayName()).thenReturn("dummy"); |
| 116 | + when(iterationInfo.getName()).thenReturn("dummy"); |
| 117 | + |
| 118 | + final ArgumentCaptor<TestResult> scheduled = ArgumentCaptor.forClass(TestResult.class); |
| 119 | + |
| 120 | + allureSpock2.beforeIteration(iterationInfo); |
| 121 | + allureSpock2.beforeIteration(iterationInfo); |
| 122 | + |
| 123 | + verify(lifecycle, times(2)).scheduleTestCase(scheduled.capture()); |
| 124 | + final List<TestResult> captured = scheduled.getAllValues(); |
| 125 | + assertThat(captured) |
| 126 | + .hasSize(2) |
| 127 | + .extracting(TestResult::getUuid) |
| 128 | + .doesNotContainNull(); |
| 129 | + assertThat(captured.get(0).getUuid()).isNotEqualTo(captured.get(1).getUuid()); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + void shouldIgnoreErrorAndAfterIterationWhenUuidMissing() { |
| 134 | + final io.qameta.allure.AllureLifecycle lifecycle = mock(io.qameta.allure.AllureLifecycle.class); |
| 135 | + final AllureSpock2 allureSpock2 = new AllureSpock2(lifecycle); |
| 136 | + |
| 137 | + allureSpock2.error(mock(org.spockframework.runtime.model.ErrorInfo.class)); |
| 138 | + allureSpock2.afterIteration(mock(org.spockframework.runtime.model.IterationInfo.class)); |
| 139 | + |
| 140 | + verifyNoInteractions(lifecycle); |
| 141 | + } |
| 142 | + |
| 143 | + private static final class DummySpec { |
| 144 | + public void dummy() { |
| 145 | + // noop |
| 146 | + } |
| 147 | + } |
| 148 | + |
82 | 149 | @Test |
83 | 150 | void shouldStoreTestsInformation() { |
84 | 151 | final AllureResults results = runClasses(OneTest.class); |
|
0 commit comments