Search in sources :

Example 21 with DynamicTest

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);
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 22 with DynamicTest

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()"));
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 23 with 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();
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) DynamicDescendantFilter(org.junit.jupiter.engine.descriptor.DynamicDescendantFilter) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestTemplateInvocationTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor) JupiterTestDescriptor(org.junit.jupiter.engine.descriptor.JupiterTestDescriptor) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 24 with DynamicTest

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();
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) DynamicDescendantFilter(org.junit.jupiter.engine.descriptor.DynamicDescendantFilter) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestTemplateInvocationTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor) JupiterTestDescriptor(org.junit.jupiter.engine.descriptor.JupiterTestDescriptor) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 25 with DynamicTest

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);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TestFactory(org.junit.jupiter.api.TestFactory) Iterator(java.util.Iterator) Collection(java.util.Collection) HashMap(java.util.HashMap) Function(java.util.function.Function) List(java.util.List) Employee(com.baeldung.helpers.Employee) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) DynamicTest(org.junit.jupiter.api.DynamicTest) EmployeeDao(com.baeldung.helpers.EmployeeDao) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ThrowingConsumer(org.junit.jupiter.api.function.ThrowingConsumer) EmployeeDao(com.baeldung.helpers.EmployeeDao) Employee(com.baeldung.helpers.Employee) DynamicTest(org.junit.jupiter.api.DynamicTest) TestFactory(org.junit.jupiter.api.TestFactory)

Aggregations

DynamicTest (org.junit.jupiter.api.DynamicTest)25 Test (org.junit.jupiter.api.Test)16 TestFactory (org.junit.jupiter.api.TestFactory)14 Stream (java.util.stream.Stream)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)7 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)7 ReturnCode (com.github.robozonky.api.ReturnCode)6 Event (com.github.robozonky.api.notifications.Event)6 EventListener (com.github.robozonky.api.notifications.EventListener)6 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)6 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)6 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)6 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)6 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)6 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)6 PurchasingCompletedEvent (com.github.robozonky.api.notifications.PurchasingCompletedEvent)6 PurchasingStartedEvent (com.github.robozonky.api.notifications.PurchasingStartedEvent)6 RoboZonkyEndingEvent (com.github.robozonky.api.notifications.RoboZonkyEndingEvent)6 SaleOfferedEvent (com.github.robozonky.api.notifications.SaleOfferedEvent)6 SellingCompletedEvent (com.github.robozonky.api.notifications.SellingCompletedEvent)6