1 package org.simantics.tests.modelled.junit.v2;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import java.util.stream.Collectors;
8 import org.eclipse.core.runtime.NullProgressMonitor;
9 import org.junit.runner.Description;
10 import org.junit.runner.Result;
11 import org.junit.runner.notification.RunListener;
12 import org.junit.runner.notification.RunNotifier;
13 import org.junit.runners.ParentRunner;
14 import org.junit.runners.model.InitializationError;
15 import org.simantics.Simantics;
16 import org.simantics.db.testing.common.AcornTests;
17 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
18 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
20 public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
22 public static final String EXCLUSION_FILTER = "org.simantics.tests.modelled.excludeFilter";
24 private final List<ModelledSTSSuiteRunner> children;
26 public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
30 Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
31 String exclusionFilter = System.getProperty(EXCLUSION_FILTER);
32 Collection<ModelledSTSSuite> filtered;
33 if (exclusionFilter != null) {
34 String[] filters = exclusionFilter.split(",");
35 filtered = suites.stream().filter(s -> !startsWithAny(s, filters)).collect(Collectors.toList());
40 List<ModelledSTSSuite> sorted = filtered.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
43 children = new ArrayList<>(sorted.size());
44 for (ModelledSTSSuite suite : sorted) {
45 children.add(new ModelledSTSSuiteRunner(suite));
47 } catch (Exception e) {
48 throw new InitializationError(e);
52 private static boolean startsWithAny(ModelledSTSSuite suite, String[] filters) {
53 for (String filter : filters) {
54 if (suite.getName().contains(filter)) {
62 protected List<ModelledSTSSuiteRunner> getChildren() {
67 protected Description describeChild(ModelledSTSSuiteRunner child) {
68 return child.getDescription();
72 public void run(RunNotifier notifier) {
73 notifier.addListener(new RunListener() {
76 public void testRunFinished(Result result) throws Exception {
84 protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
86 // TODO: Add coverage reporting to ModelledSTSRunner
87 // CombinedCoverage cover = child.getCoverage();
88 // CoverageBuilder b = new CoverageBuilder();
91 public void initialize() throws InitializationError {
94 public void deinitialize() throws Exception {
97 private void initialize0() throws Exception {
98 AcornTests.newSimanticsWorkspace(null, null);
102 private void deinitialize0() throws Exception {
104 Simantics.shutdown(new NullProgressMonitor());