如何使用JUnit测试Sirius表达式

时间:2019-02-18 19:29:41

标签: java eclipse junit eclipse-sirius

我正在使用Sirius构建一组图。图中的某些元素使用Java service methods,我想使用类似JUnit(理想情况下为JUnit 5,但这不是必需)进行测试。是否有任何示例或更好的文档来说明如何执行此操作?

我知道我可以直接测试服务方法,但是我想要的是一种强制测试通过模型本身的方法,即使用.odesign文件中指定的表达式和映射。

我已经找到并尝试使用一些Sirius内部测试基础结构- this class是我大部分时间都在其中的地方。不幸的是,我在逆向工程该类结构中做出的所有决策时遇到了麻烦,因此我有点不知所措。我目前收到此错误:

java.lang.RuntimeException: Impossible to create the session.
    at org.eclipse.sirius.tests.support.api.SiriusTestCase.createSession(SiriusTestCase.java:490)
    at org.eclipse.sirius.tests.support.api.SiriusTestCase.createOrLoadAndOpenSession(SiriusTestCase.java:448)
    at org.eclipse.sirius.tests.support.api.SiriusTestCase.genericSetUp(SiriusTestCase.java:393)
    at org.eclipse.sirius.tests.support.api.SiriusTestCase.genericSetUp(SiriusTestCase.java:322)
    at org.eclipse.sirius.tests.support.api.SiriusTestCase.genericSetUp(SiriusTestCase.java:296)
    at my.test.class.setUp(ServicesTest.java:32)
    at junit.framework.TestCase.runBare(TestCase.java:139)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:252)
    at junit.framework.TestSuite.run(TestSuite.java:247)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:232)
    at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness.lambda$0(PlatformUITestHarness.java:45)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4906)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4475)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1173)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1062)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:636)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:563)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:151)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:155)
    at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:55)
    at org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:46)
    at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:49)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:595)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1501)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1474)
Caused by: org.eclipse.core.runtime.CoreException: Session creation failed
    at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.prepareDAnalysis(SessionFactoryImpl.java:281)
    at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.createSessionResource(SessionFactoryImpl.java:237)
    at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.createSession(SessionFactoryImpl.java:89)
    at org.eclipse.sirius.business.api.session.DefaultLocalSessionCreationOperation.execute(DefaultLocalSessionCreationOperation.java:71)
    at org.eclipse.sirius.tests.support.api.SiriusTestCase$2.execute(SiriusTestCase.java:480)
    at org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:110)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2295)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2322)
    at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:131)
    at org.eclipse.sirius.tests.support.api.SiriusTestCase.createSession(SiriusTestCase.java:488)
    ... 49 more
Caused by: java.net.UnknownServiceException: protocol doesn't support output
    at java.net.URLConnection.getOutputStream(URLConnection.java:843)
    at org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createOutputStream(URIHandlerImpl.java:154)
    at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createOutputStream(ExtensibleURIConverterImpl.java:349)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1041)
    at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.prepareDAnalysis(SessionFactoryImpl.java:279)
    ... 58 more

总而言之,我正在寻找示例,文档,甚至只是一个API,我可以使用它们使用诸如JUnit之类的测试框架来测试Sirius表达式。

谢谢。

0 个答案:

没有答案