Search in sources :

Example 1 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class TestClassWithTemplate method resolvingUniqueIdWithWrongParamsResolvesNothing.

@Test
@TrackLogRecords
void resolvingUniqueIdWithWrongParamsResolvesNothing(LogRecordListener listener) {
    UniqueId uniqueId = uniqueIdForMethod(HerTestClass.class, "test7(java.math.BigDecimal)");
    EngineDiscoveryRequest request = request().selectors(selectUniqueId(uniqueId)).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    // 
    assertThat(listener.stream(JavaElementsResolver.class, Level.WARNING).map(LogRecord::getMessage)).contains("Unique ID '" + uniqueId + "' could only be partially resolved. " + "All resolved segments will be executed; however, the following segments " + "could not be resolved: [Segment [type = 'method', value = 'test7(java.math.BigDecimal)']]");
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LogRecord(java.util.logging.LogRecord) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 2 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class TestClassWithTemplate method resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing.

@Test
@TrackLogRecords
void resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing(LogRecordListener listener) {
    UniqueId uniqueId = engineId().append("bogus", "enigma");
    UniqueIdSelector selector = selectUniqueId(uniqueId);
    EngineDiscoveryRequest request = request().selectors(selector).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    // 
    assertThat(listener.stream(JavaElementsResolver.class, Level.WARNING).map(LogRecord::getMessage)).contains("Unique ID '" + uniqueId + "' could not be resolved.");
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LogRecord(java.util.logging.LogRecord) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 3 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method executesAllTestsForNotFilterableChildRunnerOfSuite.

@TrackLogRecords
@Test
void executesAllTestsForNotFilterableChildRunnerOfSuite(LogRecordListener logRecordListener) {
    Class<?> suiteClass = JUnit4SuiteOfSuiteWithFilterableChildRunner.class;
    Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(suiteClass)).filters((PostDiscoveryFilter) descriptor -> includedIf(descriptor.getDisplayName().contains("#1")));
    TestPlan testPlan = discover(request);
    logRecordListener.clear();
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(4);
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", suiteClass.getName(), testClass.getName(), "Test #0", "Test #1");
    // 
    assertThat(logRecordListener.stream(RunnerTestDescriptor.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly(// 
    "Runner " + Suite.class.getName() + " (used on class " + suiteClass.getName() + ")" + " was not able to satisfy all filter requests.");
}
Also used : JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) ParameterizedTestCase(org.junit.vintage.engine.samples.junit4.ParameterizedTestCase) Launcher(org.junit.platform.launcher.Launcher) TestPlan(org.junit.platform.launcher.TestPlan) JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) TagFilter.excludeTags(org.junit.platform.launcher.TagFilter.excludeTags) Categories(org.junit.vintage.engine.samples.junit4.Categories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) FilterResult.includedIf(org.junit.platform.engine.FilterResult.includedIf) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Level(java.util.logging.Level) LinkedHashMap(java.util.LinkedHashMap) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) ENGINE_ID(org.junit.vintage.engine.descriptor.VintageTestDescriptor.ENGINE_ID) Map(java.util.Map) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords) LauncherFactory(org.junit.platform.launcher.core.LauncherFactory) NotFilterableRunner(org.junit.vintage.engine.samples.junit4.NotFilterableRunner) JUnit4SuiteOfSuiteWithFilterableChildRunner(org.junit.vintage.engine.samples.junit4.JUnit4SuiteOfSuiteWithFilterableChildRunner) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) PlainJUnit4TestCaseWithTwoTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) EnclosedJUnit4TestCase(org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) LogRecord(java.util.logging.LogRecord) JUnit4SuiteWithTwoTestCases(org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithTwoTestCases) Test(org.junit.jupiter.api.Test) LogRecordListener(org.junit.platform.commons.logging.LogRecordListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) FilterResult.excluded(org.junit.platform.engine.FilterResult.excluded) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) Suite(org.junit.runners.Suite) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) TagFilter.includeTags(org.junit.platform.launcher.TagFilter.includeTags) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) TestPlan(org.junit.platform.launcher.TestPlan) LogRecord(java.util.logging.LogRecord) JUnit4SuiteOfSuiteWithFilterableChildRunner(org.junit.vintage.engine.samples.junit4.JUnit4SuiteOfSuiteWithFilterableChildRunner) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 4 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method executesAllTestsForNotFilterableRunner.

@TrackLogRecords
@Test
void executesAllTestsForNotFilterableRunner(LogRecordListener logRecordListener) {
    Class<?> testClass = JUnit4TestCaseWithNotFilterableRunner.class;
    LauncherDiscoveryRequestBuilder request = // 
    request().selectors(// 
    selectClass(testClass)).filters((PostDiscoveryFilter) descriptor -> includedIf(descriptor.getDisplayName().contains("#1")));
    TestPlan testPlan = discover(request);
    logRecordListener.clear();
    assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).hasSize(3);
    Map<TestIdentifier, TestExecutionResult> results = execute(request);
    // 
    assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactlyInAnyOrder("JUnit Vintage", testClass.getName(), "Test #0", "Test #1");
    // 
    assertThat(logRecordListener.stream(RunnerTestDescriptor.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly(// 
    "Runner " + NotFilterableRunner.class.getName() + " (used on class " + testClass.getName() + ")" + " does not support filtering and will therefore be run completely.");
}
Also used : JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) ParameterizedTestCase(org.junit.vintage.engine.samples.junit4.ParameterizedTestCase) Launcher(org.junit.platform.launcher.Launcher) TestPlan(org.junit.platform.launcher.TestPlan) JUnit4TestCaseWithNotFilterableRunner(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithNotFilterableRunner) TagFilter.excludeTags(org.junit.platform.launcher.TagFilter.excludeTags) Categories(org.junit.vintage.engine.samples.junit4.Categories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiscoverySelectors.selectClass(org.junit.platform.engine.discovery.DiscoverySelectors.selectClass) FilterResult.includedIf(org.junit.platform.engine.FilterResult.includedIf) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Level(java.util.logging.Level) LinkedHashMap(java.util.LinkedHashMap) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) ENGINE_ID(org.junit.vintage.engine.descriptor.VintageTestDescriptor.ENGINE_ID) Map(java.util.Map) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords) LauncherFactory(org.junit.platform.launcher.core.LauncherFactory) NotFilterableRunner(org.junit.vintage.engine.samples.junit4.NotFilterableRunner) JUnit4SuiteOfSuiteWithFilterableChildRunner(org.junit.vintage.engine.samples.junit4.JUnit4SuiteOfSuiteWithFilterableChildRunner) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) PlainJUnit4TestCaseWithTwoTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) EnclosedJUnit4TestCase(org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) LogRecord(java.util.logging.LogRecord) JUnit4SuiteWithTwoTestCases(org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithTwoTestCases) Test(org.junit.jupiter.api.Test) LogRecordListener(org.junit.platform.commons.logging.LogRecordListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) FilterResult.excluded(org.junit.platform.engine.FilterResult.excluded) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) Suite(org.junit.runners.Suite) PlainJUnit4TestCaseWithFiveTestMethods(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods) TagFilter.includeTags(org.junit.platform.launcher.TagFilter.includeTags) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) TestPlan(org.junit.platform.launcher.TestPlan) LogRecord(java.util.logging.LogRecord) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 5 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class TestClassWithTemplate method methodResolutionByUniqueIdWithParams.

@Test
@TrackLogRecords
void methodResolutionByUniqueIdWithParams(LogRecordListener listener) {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(HerTestClass.class, "test7(java.lang.String)").toString());
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(2, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(HerTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(HerTestClass.class, "test7(java.lang.String)"));
    assertThat(listener.stream(JavaElementsResolver.class)).isEmpty();
}
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) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Aggregations

Test (org.junit.jupiter.api.Test)7 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)7 DynamicTest (org.junit.jupiter.api.DynamicTest)5 UniqueId (org.junit.platform.engine.UniqueId)5 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)5 LogRecord (java.util.logging.LogRecord)4 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Level (java.util.logging.Level)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)2 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)2 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)2 LogRecordListener (org.junit.platform.commons.logging.LogRecordListener)2 CollectionUtils.getOnlyElement (org.junit.platform.commons.util.CollectionUtils.getOnlyElement)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 FilterResult.excluded (org.junit.platform.engine.FilterResult.excluded)2 FilterResult.includedIf (org.junit.platform.engine.FilterResult.includedIf)2 TestDescriptor (org.junit.platform.engine.TestDescriptor)2 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)2