Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping in Xtext(Scoping in XTEXT for JUNIT Tests)
icon5.gif  Scoping in Xtext [message #1160369] Tue, 29 October 2013 04:58 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hello all,
I have a xtend class Sample.xtend and I have injected scope provider in it,
something like:

@Inject
private IScopeProvider scopeProvider

I am using:
val scope = scopeProvider.getScope(ref, getReferenceFeature(ref))


"ref" is an EObject and "getReferenceFeature(ref)" method is defined by me to find EReference.

When I run the tool this thing works perfectly fine BUT, when I call this method in my JUNIT test case, I GET A NULL POINTER EXCEPTION at val scope = scopeProvider.getScope(ref, getReferenceFeature(ref))
.

All the data needed for test case is present but I get exception at that place. Do I have to do any initialization or some other stuff related to Scoping before I can use it in my test case ??


Thanks in advance Smile




Arshad
icon1.gif  Re: Scoping in Xtext [message #1160462 is a reply to message #1160369] Tue, 29 October 2013 06:24 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi all,
Some more info.
Basically here my scopeProvider is null, so how do I avoid it when running test cases. It works fine when I run the tool.


Thanks in advance Smile


Arshad
Re: Scoping in Xtext [message #1160495 is a reply to message #1160462] Tue, 29 October 2013 06:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
hi,

are you sure your test setup is correct?

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class SampleTest {

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon5.gif  Re: Scoping in Xtext [message #1160557 is a reply to message #1160495] Tue, 29 October 2013 07:48 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
Thanks for your reply.
Yes, the set up is correct, the only difference is I am using XtextRunner3.

But, I have one Scoping class written by myself i.e. SomeScopeProvider.java and when I inject using:
@Inject
private IScopeProvider scopeProvider;

At runtime (i.e. when I launch my tool) this scopeProvider is of type SomeScopeProvider. But when I run the test cases it is null.

Any help??

Thanks in advance Smile


Arshad
Re: Scoping in Xtext [message #1160575 is a reply to message #1160557] Tue, 29 October 2013 08:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

does it work if you directly inject YourdslScopeProvider?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scoping in Xtext [message #1160582 is a reply to message #1160575] Tue, 29 October 2013 08:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
P.S: what is XtextRunner3???

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon1.gif  Re: Scoping in Xtext [message #1160605 is a reply to message #1160582] Tue, 29 October 2013 08:27 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi,
XtextRunner3 extends BlockJUnit4ClassRunner. Same as XtextRunner. Anyways I have changed it to XtextRunner Still the same problem. I will write the code snippet below:

Class Sample {
@Inject
private IScopeProvider scopeProvider;


public void someMethod(){
.......
......
......
scopeProvider.getScope(......); // scopeProvider is NULL here when I call this method in JUNIT but it works fine when i launch my tool.
}

}
---------------------------------------------------------------------------------------

My JUNIT class is:
@InjectWith(value = MyDslInjectorProvider.class)
@RunWith(value = XtextRunner.class)
public class ModelTest {
public void testsomeMethod(){
Here calling someMethod()
}
}
---------------------------------------------------------------------------------------

I have defined one CUSTOM Scope provider class SomeScopeProvider.java and scopeProvider is of type SomeScopeProvider at runtime and NULL while executing tests.

Here I have given complete description. Please ignore earlier messages.

Thanks in advance Smile




Arshad
Re: Scoping in Xtext [message #1160608 is a reply to message #1160605] Tue, 29 October 2013 08:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Sorry have no idea on that .
Can you retry that with a new Xtext project?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon5.gif  Re: Scoping in Xtext [message #1160620 is a reply to message #1160608] Tue, 29 October 2013 08:36 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
But if I write a setter method for scopeProvider in Sample class and call this before the test case is executed it works fine.
I just wanted to know is it a good practice to do that???

Thanks Smile


Arshad
Re: Scoping in Xtext [message #1160621 is a reply to message #1160620] Tue, 29 October 2013 08:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13493
Registered: July 2009
Senior Member
Hi,

it should work with @Inject and in my project it works with > 1000 Tests


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Using Xtext as a language translator
Next Topic:Using XExpression somewhere else than in operation bodies
Goto Forum:
  


Current Time: Sat Jul 11 06:19:32 GMT 2020

Powered by FUDForum. Page generated in 0.02390 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top