1 package org.simantics.tests.modelled.junit.v2;
3 import java.util.ArrayList;
7 import org.junit.runner.Description;
8 import org.junit.runner.notification.Failure;
9 import org.junit.runner.notification.RunNotifier;
10 import org.junit.runners.ParentRunner;
11 import org.junit.runners.model.InitializationError;
12 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
13 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
14 import org.simantics.tests.modelled.utils.ModelledSTSTest;
15 import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
17 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
19 private final ModelledSTSSuite suite;
20 private final List<ModelledSTSTestRunner> children;
21 private Map<String, List<CommandSessionVariable>> storedVariables;
23 public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
24 super(ModelledSTSSuiteRunner.class);
26 this.children = new ArrayList<>(suite.getChildren().size());
27 for (ModelledSTSTest test : suite.getSortedChildren()) {
28 children.add(new ModelledSTSTestRunner(test));
33 protected String getName() {
34 return suite.getName();
38 protected List<ModelledSTSTestRunner> getChildren() {
43 protected Description describeChild(ModelledSTSTestRunner child) {
44 return child.getDescription();
48 protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
49 Description description = describeChild(child);
50 if (isIgnored(child)) {
51 notifier.fireTestIgnored(description);
54 List<CommandSessionVariable> variables = new ArrayList<>();
55 for (String dep : child.getTest().getDependencies()) {
56 List<CommandSessionVariable> storedVars = storedVariables.get(dep);
57 if (storedVars != null) {
58 variables.addAll(storedVars);
61 List<CommandSessionVariable> newVars = child.runWithVars(variables);
62 storedVariables.put(child.getTest().getName(), newVars);
63 notifier.fireTestFinished(description);
64 } catch (Exception e) {
65 notifier.fireTestFailure(new Failure(description, e));
71 protected boolean isIgnored(ModelledSTSTestRunner child) {
72 return child.isIgnored();
75 public CombinedCoverage getCoverage() {
76 return suite.getCoverage();