1 package org.simantics.tests.modelled.junit.v2;
4 import java.util.stream.Collectors;
6 import org.junit.runner.Description;
7 import org.junit.runner.notification.Failure;
8 import org.junit.runner.notification.RunNotifier;
9 import org.junit.runners.ParentRunner;
10 import org.simantics.scl.compiler.commands.CommandSession;
11 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
12 import org.simantics.scl.osgi.SCLOsgi;
13 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
14 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
16 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
18 private final ModelledSTSSuite suite;
19 private CommandSession commandSession;
21 public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws Exception {
22 super(ModelledSTSSuiteRunner.class);
27 protected String getName() {
28 return suite.getName();
32 protected List<ModelledSTSTestRunner> getChildren() {
33 return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList());
37 protected Description describeChild(ModelledSTSTestRunner child) {
38 return child.getDescription();
42 protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
43 Description description = describeChild(child);
44 if (isIgnored(child)) {
45 notifier.fireTestIgnored(description);
47 notifier.fireTestStarted(description);
49 child.run(getCommandSession());
50 notifier.fireTestFinished(description);
51 STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession());
52 } catch (Throwable e) {
53 notifier.fireTestFailure(new Failure(description, e));
59 protected boolean isIgnored(ModelledSTSTestRunner child) {
60 return child.isIgnored();
63 public void setCommandSesssion(CommandSession commandSession) {
64 this.commandSession = commandSession;
67 public CommandSession getCommandSession() {
68 if (commandSession == null)
69 commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
70 return commandSession;
73 public CombinedCoverage getCoverage() {
74 return suite.getCoverage();