Problems with linking in Xtext unit testing with multiple DSLs [message #1831781] |
Fri, 28 August 2020 16:45  |
Eclipse User |
|
|
|
Hello,
I am trying to write unit tests for multiple DSLs which can link to each other. Basically they can define "concepts", with the availability to define sub/super concept relations with the syntax of concept Concept1 is a Concept2 meaning that the concept Concept1 is a subconcept of Concept2.
This is a example of what my test is like:
@RunWith(typeof(XtextRunner))
@InjectWith(typeof(DslTwoUITestInjectorProvider))
class DslTwoValidationTest {
@Inject
ValidationTestHelper validationTestHelper
@Inject
Provider<XtextResourceSet> resourceSetProvider
static val DSL_ONE = '''
DslOne 1.0
concept Concept1
'''
static val DSL_TWO = '''
DslTwo 1.0
concept Concept2 is a Concept3
'''
@Test
def void test() {
val resourceSet = resourceSetProvider.get
val dslOne = resourceSet.createResource(URI.createURI("dslOne.dslOne")) as XtextResource
dslOne.load(new StringInputStream(DSL_ONE), emptyMap)
val dslTwo = resourceSet.createResource(URI.createURI("dslTwo.dslTwo")) as XtextResource
validationTestHelper.assertNoErrors(dsl Two)
}
}
With my injector provider as follows
public class DslTwoUITestInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
private GlobalStateMemento stateBeforeInjectorCreation;
private GlobalStateMemento stateAfterInjectorCreation;
private Injector injector;
private Injector dslOneInjector;
private static DslTwoUITestInjectorProvider instance;
static {
GlobalRegistries.initializeDefaults();
}
@Override
public Injector getInjector() {
if (injector == null) {
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
this.injector = internalCreateInjector();
instance = this;
stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
}
return injector;
}
public Injector getDslOneInjectorInjector() {
return dslOneInjector;
}
private Injector internalCreateInjector() {
dslOneInjector = new DslOneUiInjectorProvider().getInjector();
return new DslTwoUiInjectorProvider().getInjector();
}
@Override
public void restoreRegistry() {
stateBeforeInjectorCreation.restoreGlobalState();
}
@Override
public void setupRegistry() {
getInjector();
stateAfterInjectorCreation.restoreGlobalState();
}
public static DslTwoUITestInjectorProvider getInstance() {
return instance;
}
}
When dslOne is loaded, in my code a model object of DSLTwo is created and stored in the contents of the dslOne resource, and the created DSLTwo looks like this:
So the dslTwo resource should by linking have access to Concept3. However, when I run the test, it fails because there is an error on the dslTwo resource that states that it could not resolve the reference to concept Concept3. When I actually run my application and do the same thing that the test is doing, the dslTwo resource does not have a problem resolving the reference to concept Concept3.
Any ideas what is going wrong?
[Updated on: Fri, 28 August 2020 16:46] by Moderator
|
|
|
|
|
Re: Problems with linking in Xtext unit testing with multiple DSLs [message #1832175 is a reply to message #1831909] |
Thu, 10 September 2020 19:15  |
Eclipse User |
|
|
|
Hello,
Thank you for the quick response. I was wondering if you could point me to some UI tests that have linking between multiple DSLs, where they are all contained in the same project for visibility?
Or if there are no examples of that, could you point me to where I could learn how to programmatically create Xtext projects in a UI test that would contain my resource set?
The RCP we are developing is set up so that I believe I need to run these validation tests as UI tests, even if that is not best practice, as some things are done when the RCP is running that I would like to test in my validation tests (for example we have built-in DSL files that are created at runtime when other DSL files are created, and while I could theoretically manually create them and run the validation test not as a UI test I would like to include this aspect in my test)
Best,
Louis
|
|
|
Powered by
FUDForum. Page generated in 0.06905 seconds