org.junit.platform.engine.TestTag Java Examples

The following examples show how to use org.junit.platform.engine.TestTag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JunitPlatformDoer.java    From jeka with Apache License 2.0 6 votes vote down vote up
private static JkTestResult.JkFailure toFailure(TestExecutionSummary.Failure failure) {
    JkTestResult.JkTestIdentifier.JkType type;
    switch (failure.getTestIdentifier().getType()) {
        case CONTAINER:
            type = JkTestResult.JkTestIdentifier.JkType.CONTAINER;
            break;
        case CONTAINER_AND_TEST:
            type = JkTestResult.JkTestIdentifier.JkType.CONTAINER_AND_TEST;
            break;
        default:
            type = JkTestResult.JkTestIdentifier.JkType.TEST;
            break;
    }
    String testId = failure.getTestIdentifier().getUniqueId();
    String displayName = failure.getTestIdentifier().getDisplayName();
    Set<String> tags = failure.getTestIdentifier().getTags().stream().map(TestTag::toString)
            .collect(Collectors.toSet());
    JkTestResult.JkTestIdentifier id = JkTestResult.JkTestIdentifier.of(type, testId, displayName, tags);
    return JkTestResult.JkFailure.of(id, failure.getException().getMessage(),
            failure.getException().getStackTrace());
}
 
Example #2
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void tags_of_test_classes() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(TestClassWithTags.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor testClass = getOnlyElement(descriptor.getChildren());
    assertThat(testClass.getTags()).containsOnly(TestTag.create("tag-one"), TestTag.create("tag-two"));

    Set<? extends TestDescriptor> concreteRules = getAllLeafs(testClass);
    assertThat(concreteRules).as("concrete rules").hasSize(3);
    concreteRules.forEach(concreteRule ->
            assertThat(concreteRule.getTags()).containsOnly(TestTag.create("tag-one"), TestTag.create("tag-two"))
    );
}
 
Example #3
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void meta_tag_of_test_classes() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(TestClassWithMetaTag.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor testClass = getOnlyElement(descriptor.getChildren());
    assertThat(testClass.getTags()).containsOnly(TestTag.create("meta-tag-one"), TestTag.create("meta-tag-two"));

    Set<? extends TestDescriptor> concreteRules = getAllLeafs(testClass);
    assertThat(concreteRules).as("concrete rules").hasSize(3);
    concreteRules.forEach(concreteRule ->
            assertThat(concreteRule.getTags()).containsOnly(TestTag.create("meta-tag-one"), TestTag.create("meta-tag-two"))
    );
}
 
Example #4
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void meta_tags_of_test_classes() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(TestClassWithMetaTags.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    TestDescriptor testClass = getOnlyElement(descriptor.getChildren());
    assertThat(testClass.getTags()).containsOnly(TestTag.create("meta-tags-one"), TestTag.create("meta-tags-two"));

    Set<? extends TestDescriptor> concreteRules = getAllLeafs(testClass);
    assertThat(concreteRules).as("concrete rules").hasSize(3);
    concreteRules.forEach(concreteRule ->
            assertThat(concreteRule.getTags()).containsOnly(TestTag.create("meta-tags-one"), TestTag.create("meta-tags-two"))
    );
}
 
Example #5
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Test
void complex_tags() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(ComplexTags.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    Map<UniqueId, Set<TestTag>> tagsById = new HashMap<>();
    descriptor.accept(d -> tagsById.put(d.getUniqueId(), d.getTags()));

    assertThat(getTagsForIdEndingIn(ComplexTags.class.getSimpleName(), tagsById))
            .containsOnly(TestTag.create("library-tag"));

    assertThat(getTagsForIdEndingIn(TestClassWithTags.class.getSimpleName(), tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("rules-tag"),
                    TestTag.create("tag-one"),
                    TestTag.create("tag-two"));

    assertThat(getTagsForIdEndingIn(TestClassWithTags.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("rules-tag"),
                    TestTag.create("tag-one"),
                    TestTag.create("tag-two"));

    assertThat(getTagsForIdEndingIn(ComplexTags.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("field-tag"));

    assertThat(getTagsForIdEndingIn(ComplexTags.METHOD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-tag"),
                    TestTag.create("method-tag"));
}
 
Example #6
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private List<Label> getTags(final TestIdentifier testIdentifier) {
    return testIdentifier.getTags().stream()
            .map(TestTag::getName)
            .map(ResultsUtils::createTagLabel)
            .collect(Collectors.toList());
}
 
Example #7
Source File: AbstractArchUnitTestDescriptor.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private Set<TestTag> findTagsOn(AnnotatedElement annotatedElement) {
    return AnnotationSupport.findRepeatableAnnotations(annotatedElement, ArchTag.class)
            .stream()
            .map(annotation -> TestTag.create(annotation.value()))
            .collect(toSet());
}
 
Example #8
Source File: AbstractArchUnitTestDescriptor.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public Set<TestTag> getTags() {
    Set<TestTag> result = new HashSet<>(tags);
    result.addAll(getParent().map(TestDescriptor::getTags).orElse(emptySet()));
    return result;
}
 
Example #9
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void tags_of_rule_fields() {
    TestDescriptor testField = getOnlyChildWithDescriptorContaining(FIELD_WITH_TAG_NAME, TestFieldWithTags.class);

    assertThat(testField.getTags()).containsOnly(TestTag.create("field-tag-one"), TestTag.create("field-tag-two"));
}
 
Example #10
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void meta_tag_of_rule_fields() {
    TestDescriptor testField = getOnlyChildWithDescriptorContaining(FIELD_WITH_META_TAG_NAME, TestFieldWithMetaTag.class);

    assertThat(testField.getTags()).containsOnly(TestTag.create("field-meta-tag-one"), TestTag.create("field-meta-tag-two"));
}
 
Example #11
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void meta_tags_of_rule_fields() {
    TestDescriptor testField = getOnlyChildWithDescriptorContaining(FIELD_WITH_META_TAGS_NAME, TestFieldWithMetaTags.class);

    assertThat(testField.getTags()).containsOnly(TestTag.create("field-meta-tags-one"), TestTag.create("field-meta-tags-two"));
}
 
Example #12
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void tags_of_rule_methods() {
    TestDescriptor testMethod = getOnlyChildWithDescriptorContaining(METHOD_WITH_TAG_NAME, TestMethodWithTags.class);

    assertThat(testMethod.getTags()).containsOnly(TestTag.create("method-tag-one"), TestTag.create("method-tag-two"));
}
 
Example #13
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void meta_tag_of_rule_methods() {
    TestDescriptor testMethod = getOnlyChildWithDescriptorContaining(METHOD_WITH_META_TAG_NAME, TestMethodWithMetaTag.class);

    assertThat(testMethod.getTags()).containsOnly(TestTag.create("method-meta-tag-one"), TestTag.create("method-meta-tag-two"));
}
 
Example #14
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void meta_tags_of_rule_methods() {
    TestDescriptor testMethod = getOnlyChildWithDescriptorContaining(METHOD_WITH_META_TAGS_NAME, TestMethodWithMetaTags.class);

    assertThat(testMethod.getTags()).containsOnly(TestTag.create("method-meta-tags-one"), TestTag.create("method-meta-tags-two"));
}
 
Example #15
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Test
void complex_meta_tags() {
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withClass(ComplexMetaTags.class);

    TestDescriptor descriptor = testEngine.discover(discoveryRequest, engineId);

    Map<UniqueId, Set<TestTag>> tagsById = new HashMap<>();
    descriptor.accept(d -> tagsById.put(d.getUniqueId(), d.getTags()));

    assertThat(getTagsForIdEndingIn(ComplexMetaTags.class.getSimpleName(), tagsById))
            .containsOnly(TestTag.create("library-meta-tag"));

    assertThat(getTagsForIdEndingIn(TestClassWithMetaTag.class.getSimpleName(), tagsById))
            .containsOnly(
                    TestTag.create("library-meta-tag"),
                    TestTag.create("rules-meta-tag"),
                    TestTag.create("meta-tag-one"),
                    TestTag.create("meta-tag-two"));

    assertThat(getTagsForIdEndingIn(TestClassWithMetaTags.class.getSimpleName(), tagsById))
            .containsOnly(
                    TestTag.create("library-meta-tag"),
                    TestTag.create("rules-meta-tag"),
                    TestTag.create("meta-tags-one"),
                    TestTag.create("meta-tags-two"));

    assertThat(getTagsForIdEndingIn(TestClassWithMetaTag.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-meta-tag"),
                    TestTag.create("rules-meta-tag"),
                    TestTag.create("meta-tag-one"),
                    TestTag.create("meta-tag-two"));

    assertThat(getTagsForIdEndingIn(TestClassWithMetaTags.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-meta-tag"),
                    TestTag.create("rules-meta-tag"),
                    TestTag.create("meta-tags-one"),
                    TestTag.create("meta-tags-two"));

    assertThat(getTagsForIdEndingIn(ComplexMetaTags.FIELD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-meta-tag"),
                    TestTag.create("field-meta-tag"));

    assertThat(getTagsForIdEndingIn(ComplexMetaTags.METHOD_RULE_NAME, tagsById))
            .containsOnly(
                    TestTag.create("library-meta-tag"),
                    TestTag.create("method-meta-tag"));
}
 
Example #16
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private Set<TestTag> getTagsForIdEndingIn(String suffix, Map<UniqueId, Set<TestTag>> tagsById) {
    UniqueId matchingId = tagsById.keySet().stream()
            .filter(id -> getLast(id.getSegments()).getValue().endsWith(suffix))
            .collect(onlyElement());
    return tagsById.get(matchingId);
}