Skip to main content



      Home
Home » Modeling » EMF » JUnit + ResourceSetListener
JUnit + ResourceSetListener [message #1837232] Mon, 25 January 2021 11:03 Go to next message
Eclipse UserFriend
Hi EMFers!

We are writing a customised ResourceSetListener (to log changes on Papyrus Models) and are trying to unit test the thing (essentially writing regression tests to see whether it reacts to "the right" changes).

To do so, we are trying to programmatically create ResourceSetChangeEvents in JUnit. Currently, this fails with an IllegalArgumentException, because we are unable to retrieve the TransactionalEditingDomain we are trying to retrieve (through TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain()).

Does anyone have input how you would go about testing these Listeners, or examples of such tests? I haven't manage to find anything suitable...

Cheers,
Grischa
Re: JUnit + ResourceSetListener [message #1837236 is a reply to message #1837232] Mon, 25 January 2021 11:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Grischa,

If you're testing extensions of Papyrus, you may find it useful to employ the org.eclipse.papyrus.junit.utils.rules.ModelSetFixture class in your tests. This creates a complete (as complete as you need it) ModelSet for consistency with the Papyrus editing environment. Then your tests can drive changes in the resources in this fixture, and the TransactionalEditingDomain that manages the ModelSet will send the events that your listeners need.

This may be the easiest strategy to get working, because it provides all of the usual machinery and you can use Papyrus to create models to drive your tests.

Alternatively, mocking frameworks like PowerMock may be able to mock classes such as ResourceSetChangeEvent so that you can supply your tests with only the absolute minimum required of the API. I have not tried this in my own tests but I don't see why it shouldn't work. Mocking frameworks generally employ low-level JVM APIs to constructs objects, etc. so that assertions like the one giving you the IllegalArgumentException would be bypassed.

HTH,
Christian
Re: JUnit + ResourceSetListener [message #1837263 is a reply to message #1837236] Tue, 26 January 2021 07:44 Go to previous message
Eclipse UserFriend
Great, thanks Christian! We will try the ModelSetFixture :)

Cheers,
Grischa
Previous Topic:EOperation body annotation in subclass
Next Topic:Resolve an EClass that is a Proxy
Goto Forum:
  


Current Time: Sun May 11 17:15:37 EDT 2025

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

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

Back to the top