diff --git a/src/main/java/co/helmethair/scalatest/runtime/Discovery.java b/src/main/java/co/helmethair/scalatest/runtime/Discovery.java index ce5ef49..a54f73a 100644 --- a/src/main/java/co/helmethair/scalatest/runtime/Discovery.java +++ b/src/main/java/co/helmethair/scalatest/runtime/Discovery.java @@ -8,8 +8,10 @@ import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.TestTag; import org.scalatest.Suite; +import org.scalatest.TagAnnotation; import scala.Option; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -23,15 +25,16 @@ public ScalatestEngineDescriptor discover(ScalatestEngineDescriptor engineDescri Suite suite = ((Suite) classLoader.loadClass(c.getName()).newInstance()); addSuite(suite, engineDescriptor); } catch (Throwable e) { - addFailedInit(e, c.getName(), engineDescriptor); + addFailedInit(e, c, engineDescriptor); } }); return engineDescriptor; } - private void addFailedInit(Throwable cause, String className, TestDescriptor parent) { - ScalatestFailedInitDescriptor failed = new ScalatestFailedInitDescriptor(cause, className); + private void addFailedInit(Throwable cause, Class clazz, TestDescriptor parent) { + String className = clazz.getName(); + ScalatestFailedInitDescriptor failed = new ScalatestFailedInitDescriptor(cause, className, extractTags(clazz)); linkChild(parent, failed); } @@ -43,7 +46,7 @@ private void addSuite(Suite suite, TestDescriptor parent) { try { addSuite(scalatestNestedSuite, scalatestSuiteDescriptor); } catch (Throwable e) { - addFailedInit(e, scalatestNestedSuite.getClass().getName(), scalatestSuiteDescriptor); + addFailedInit(e, scalatestNestedSuite.getClass(), scalatestSuiteDescriptor); } }); } @@ -58,6 +61,13 @@ private void addTests(ScalatestSuiteDescriptor suite, Set testNames) { linkChild(suite, new ScalatestTestDescriptor(suite, testName, getTags(suite.getScalasuite(), testName)))); } + private Set extractTags(Class clazz) { + return Arrays.stream(clazz.getAnnotations()).filter(a -> + a.annotationType().isAnnotationPresent(TagAnnotation.class) + ).map(a -> TestTag.create(a.annotationType().getName())) + .collect(Collectors.toSet()); + } + private Set getTags(Suite scalasuite, String testName) { Option> tagSetOption = scalasuite.tags().get(testName); if (tagSetOption.isDefined()) {