X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSRunner.java;fp=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSRunner.java;h=c74f6efaea0fb0485f377177eba45ecfe26191d2;hb=f03893d9b643eae3f03debf7a656edbfa5b9b501;hp=0000000000000000000000000000000000000000;hpb=51006ffec13cbf8e0d9c8b07212d69478e4bdd4e;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java new file mode 100644 index 000000000..c74f6efae --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java @@ -0,0 +1,81 @@ +package org.simantics.tests.modelled.junit.v2; + +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runner.notification.RunListener; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.ParentRunner; +import org.junit.runners.model.InitializationError; +import org.simantics.Simantics; +import org.simantics.db.testing.common.AcornTests; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.tests.modelled.utils.STSSuiteTestCollector; + +public class ModelledSTSRunner extends ParentRunner { + + private CommandSession commandSession; + + public ModelledSTSRunner(Class testClass) throws Exception { + super(testClass); + initialize0(); + } + + @Override + protected List getChildren() { + return STSSuiteTestCollector.collectTests().stream().map(suite -> { + try { + return new ModelledSTSSuiteRunner(suite); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toList()); + } + + @Override + protected Description describeChild(ModelledSTSSuiteRunner child) { + return child.getDescription(); + } + + @Override + public void run(RunNotifier notifier) { + notifier.addListener(new RunListener() { + + @Override + public void testRunFinished(Result result) throws Exception { + deinitialize0(); + } + }); + super.run(notifier); + } + + @Override + protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) { + child.setCommandSesssion(commandSession); + child.run(notifier); + // TODO: Add coverage reporting to ModelledSTSRunner +// CombinedCoverage cover = child.getCoverage(); +// CoverageBuilder b = new CoverageBuilder(); + } + + public void initialize() throws InitializationError { + } + + public void deinitialize() throws Exception { + } + + private void initialize0() throws Exception { + AcornTests.newSimanticsWorkspace(null, null); + this.commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null); + initialize(); + } + + private void deinitialize0() throws Exception { + deinitialize(); + Simantics.shutdown(new NullProgressMonitor()); + } +}