use of org.junit.jupiter.api.DynamicTest in project junit5 by junit-team.
the class TestClassWithTemplate method testFactoryMethodResolutionByUniqueId.
@Test
void testFactoryMethodResolutionByUniqueId() {
Class<?> clazz = MyTestClass.class;
UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
resolver.resolveSelectors(request().selectors(selectUniqueId(factoryUid)).build(), engineDescriptor);
assertThat(engineDescriptor.getDescendants()).hasSize(2);
assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), factoryUid);
}
use of org.junit.jupiter.api.DynamicTest in project junit5 by junit-team.
the class TestClassWithTemplate method classResolutionByUniqueId.
@Test
void classResolutionByUniqueId() {
UniqueIdSelector selector = selectUniqueId(uniqueIdForClass(MyTestClass.class).toString());
resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
assertEquals(4, engineDescriptor.getDescendants().size());
List<UniqueId> uniqueIds = uniqueIds();
assertThat(uniqueIds).contains(uniqueIdForClass(MyTestClass.class));
assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test1()"));
assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test2()"));
assertThat(uniqueIds).contains(uniqueIdForTestFactoryMethod(MyTestClass.class, "dynamicTest()"));
}
use of org.junit.jupiter.api.DynamicTest in project junit5 by junit-team.
the class TestClassWithTemplate method resolvingDynamicTestByUniqueIdResolvesUpToParentTestFactory.
@Test
@TrackLogRecords
void resolvingDynamicTestByUniqueIdResolvesUpToParentTestFactory(LogRecordListener listener) {
Class<?> clazz = MyTestClass.class;
UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
UniqueId dynamicTestUid = factoryUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#1");
UniqueId differentDynamicTestUid = factoryUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#2");
resolver.resolveSelectors(request().selectors(selectUniqueId(dynamicTestUid)).build(), engineDescriptor);
assertThat(engineDescriptor.getDescendants()).hasSize(2);
assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), factoryUid);
TestDescriptor testClassDescriptor = getOnlyElement(engineDescriptor.getChildren());
TestDescriptor testFactoryDescriptor = getOnlyElement(testClassDescriptor.getChildren());
DynamicDescendantFilter dynamicDescendantFilter = getDynamicDescendantFilter(testFactoryDescriptor);
assertThat(dynamicDescendantFilter.test(dynamicTestUid)).isTrue();
assertThat(dynamicDescendantFilter.test(differentDynamicTestUid)).isFalse();
assertThat(listener.stream(JavaElementsResolver.class)).isEmpty();
}
use of org.junit.jupiter.api.DynamicTest in project junit5 by junit-team.
the class TestClassWithTemplate method resolvingDynamicContainerByUniqueIdResolvesUpToParentTestFactory.
@Test
@TrackLogRecords
void resolvingDynamicContainerByUniqueIdResolvesUpToParentTestFactory(LogRecordListener listener) {
Class<?> clazz = MyTestClass.class;
UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
UniqueId dynamicContainerUid = factoryUid.append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#1");
UniqueId differentDynamicContainerUid = factoryUid.append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#2");
UniqueId dynamicTestUid = dynamicContainerUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#1");
UniqueId differentDynamicTestUid = dynamicContainerUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#2");
resolver.resolveSelectors(request().selectors(selectUniqueId(dynamicTestUid)).build(), engineDescriptor);
assertThat(engineDescriptor.getDescendants()).hasSize(2);
assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), factoryUid);
TestDescriptor testClassDescriptor = getOnlyElement(engineDescriptor.getChildren());
TestDescriptor testFactoryDescriptor = getOnlyElement(testClassDescriptor.getChildren());
DynamicDescendantFilter dynamicDescendantFilter = getDynamicDescendantFilter(testFactoryDescriptor);
assertThat(dynamicDescendantFilter.test(dynamicTestUid)).isTrue();
assertThat(dynamicDescendantFilter.test(differentDynamicContainerUid)).isFalse();
assertThat(dynamicDescendantFilter.test(differentDynamicTestUid)).isFalse();
assertThat(listener.stream(JavaElementsResolver.class)).isEmpty();
}
use of org.junit.jupiter.api.DynamicTest in project tutorials by eugenp.
the class DynamicTestsExample method dynamicTestsForEmployeeWorkflows.
@TestFactory
Stream<DynamicTest> dynamicTestsForEmployeeWorkflows() {
List<Employee> inputList = Arrays.asList(new Employee(1, "Fred"), new Employee(2), new Employee(3, "John"));
EmployeeDao dao = new EmployeeDao();
Stream<DynamicTest> saveEmployeeStream = inputList.stream().map(emp -> DynamicTest.dynamicTest("saveEmployee: " + emp.toString(), () -> {
Employee returned = dao.save(emp.getId());
assertEquals(returned.getId(), emp.getId());
}));
Stream<DynamicTest> saveEmployeeWithFirstNameStream = inputList.stream().filter(emp -> !emp.getFirstName().isEmpty()).map(emp -> DynamicTest.dynamicTest("saveEmployeeWithName" + emp.toString(), () -> {
Employee returned = dao.save(emp.getId(), emp.getFirstName());
assertEquals(returned.getId(), emp.getId());
assertEquals(returned.getFirstName(), emp.getFirstName());
}));
return Stream.concat(saveEmployeeStream, saveEmployeeWithFirstNameStream);
}
Aggregations