1 package org.simantics.tests.modelled.junit.v2;
3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import org.junit.runner.Description;
9 import org.junit.runner.notification.Failure;
10 import org.junit.runner.notification.RunNotifier;
11 import org.junit.runners.ParentRunner;
12 import org.junit.runners.model.InitializationError;
13 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
14 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
15 import org.simantics.tests.modelled.utils.ModelledSTSTest;
16 import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
18 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
20 private final ModelledSTSSuite suite;
21 private final List<ModelledSTSTestRunner> children;
22 private Map<String, List<CommandSessionVariable>> storedVariables = new HashMap<>();
24 public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
25 super(ModelledSTSSuiteRunner.class);
27 this.children = new ArrayList<>(suite.getChildren().size());
28 for (ModelledSTSTest test : suite.getSortedChildren()) {
29 children.add(new ModelledSTSTestRunner(test));
34 protected String getName() {
35 return suite.getName();
39 protected List<ModelledSTSTestRunner> getChildren() {
44 protected Description describeChild(ModelledSTSTestRunner child) {
45 return child.getDescription();
49 protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
50 Description description = describeChild(child);
51 if (isIgnored(child)) {
52 notifier.fireTestIgnored(description);
55 List<CommandSessionVariable> variables = new ArrayList<>();
56 for (String dep : child.getTest().getDependencies()) {
57 List<CommandSessionVariable> storedVars = storedVariables.get(dep);
58 if (storedVars != null) {
59 variables.addAll(storedVars);
62 notifier.fireTestStarted(description);
63 List<CommandSessionVariable> newVars = child.runWithVars(variables);
64 storedVariables.put(child.getTest().getName(), newVars);
65 notifier.fireTestFinished(description);
66 } catch (Throwable e) {
67 notifier.fireTestFailure(new Failure(description, e));
73 protected boolean isIgnored(ModelledSTSTestRunner child) {
74 return child.isIgnored();
77 public CombinedCoverage getCoverage() {
78 return suite.getCoverage();