]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java
Merge "Resolve some dependency problems with SDK features"
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / junit / v2 / ModelledSTSRunner.java
1 package org.simantics.tests.modelled.junit.v2;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
7 import org.eclipse.core.runtime.NullProgressMonitor;
8 import org.junit.runner.Description;
9 import org.junit.runner.Result;
10 import org.junit.runner.notification.RunListener;
11 import org.junit.runner.notification.RunNotifier;
12 import org.junit.runners.ParentRunner;
13 import org.junit.runners.model.InitializationError;
14 import org.simantics.Simantics;
15 import org.simantics.db.testing.common.AcornTests;
16 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
17 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
18
19 public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
20
21     private final List<ModelledSTSSuiteRunner> children;
22
23     public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
24         super(testClass);
25         try {
26             initialize0();
27             Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
28             children = new ArrayList<>(suites.size());
29             for (ModelledSTSSuite suite : suites) {
30                 children.add(new ModelledSTSSuiteRunner(suite));
31             }
32         } catch (Exception e) {
33             throw new InitializationError(e);
34         }
35     }
36
37     @Override
38     protected List<ModelledSTSSuiteRunner> getChildren() {
39         return children;
40     }
41
42     @Override
43     protected Description describeChild(ModelledSTSSuiteRunner child) {
44         return child.getDescription();
45     }
46
47     @Override
48     public void run(RunNotifier notifier) {
49         notifier.addListener(new RunListener() {
50
51             @Override
52             public void testRunFinished(Result result) throws Exception {
53                 deinitialize0();
54             }
55         });
56         super.run(notifier);
57     }
58
59     @Override
60     protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
61         child.run(notifier);
62         // TODO: Add coverage reporting to ModelledSTSRunner
63 //        CombinedCoverage cover = child.getCoverage();
64 //        CoverageBuilder b = new CoverageBuilder();
65     }
66
67     public void initialize() throws InitializationError {
68     }
69
70     public void deinitialize() throws Exception {
71     }
72
73     private void initialize0() throws Exception {
74         AcornTests.newSimanticsWorkspace(null, null);
75         initialize();
76     }
77
78     private void deinitialize0() throws Exception {
79         deinitialize();
80         Simantics.shutdown(new NullProgressMonitor());
81     }
82 }