]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSRunner.java
Add org.simantics.db.testing plugin to SDK build
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / junit / RuntimeSTSRunner.java
1 package org.simantics.tests.modelled.junit;
2
3 import org.junit.runner.Description;
4 import org.junit.runner.Result;
5 import org.junit.runner.Runner;
6 import org.junit.runner.notification.Failure;
7 import org.junit.runner.notification.RunListener;
8 import org.junit.runner.notification.RunNotifier;
9 import org.junit.runners.ParentRunner;
10
11 public abstract class RuntimeSTSRunner<T extends Runner> extends ParentRunner<T> {
12
13     public RuntimeSTSRunner(Class<?> testClass) throws Exception {
14         super(testClass);
15     }
16
17     public abstract void initialize() throws Exception;
18
19     public abstract void deinitialize() throws Exception;
20
21     @Override
22     protected Description describeChild(Runner child) {
23         return child.getDescription();
24     }
25
26     @Override
27     public void run(RunNotifier notifier) {
28         notifier.addListener(new RunListener() {
29
30             @Override
31             public void testRunFinished(Result result) throws Exception {
32                 deinitialize();
33             }
34         });
35         super.run(notifier);
36     }
37
38     @Override
39     protected void runChild(Runner child, RunNotifier notifier) {
40         Description desc = describeChild(child);
41         notifier.fireTestStarted(desc);
42         try {
43             child.run(notifier);
44             notifier.fireTestFinished(desc);
45         } catch (Throwable e) {
46             notifier.fireTestFailure(new Failure(desc, e));
47         }
48     }
49 }