Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » testing in EMF - JUnit, Mock objects?
testing in EMF - JUnit, Mock objects? [message #491200] Tue, 13 October 2009 15:37 Go to next message
Eclipse UserFriend
Originally posted by: jan.capek.collectionspro.eu

Hi,

I am quite new to EMF. I have a general testing question. We use EMF in
conjunction with UML genmodel to generate code and test code. When
writing test cases for the generated classes (some methods have a hand
written code with business logic) we would like to use mock objects
(e.g. EasyMock framework or similar) so that we could really unit test
the objects and isolate them from the rest of the model. After
implementing a couple test cases we usually come across an issue that
prevents us from using a mock object/makes the mock object too complex.

Could anyone point me to any resources/docs/intro that cover these
topics? Does it even make sense trying to test the model like this? or
should the model be tested through the validation framework??

I have triedoogling a bit but haven't found anything related EMF + JUnit + Mock or
similar.

Thank you for any input.

Jan Capek
Re: testing in EMF - JUnit, Mock objects? [message #491210 is a reply to message #491200] Tue, 13 October 2009 16:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Jan,

Comments below.


Jan Capek wrote:
> Hi,
>
> I am quite new to EMF. I have a general testing question. We use EMF in
> conjunction with UML genmodel to generate code and test code. When
> writing test cases for the generated classes (some methods have a hand
> written code with business logic) we would like to use mock objects
> (e.g. EasyMock framework or similar) so that we could really unit test
> the objects and isolate them from the rest of the model.
I'm not familiar with that...
> After
> implementing a couple test cases we usually come across an issue that
> prevents us from using a mock object/makes the mock object too complex.
>
> Could anyone point me to any resources/docs/intro that cover these
> topics? Does it even make sense trying to test the model like this? or
> should the model be tested through the validation framework??
>
Maybe someone else is more familiar with this...
> I have triedoogling a bit but haven't found anything related EMF + JUnit + Mock or
> similar.
>
> Thank you for any input.
>
> Jan Capek
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: testing in EMF - JUnit, Mock objects? [message #492146 is a reply to message #491210] Mon, 19 October 2009 06:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.capek.collectionspro.eu

Hi Ed,

thank you for input. I will 'top-post' this as another question, maybe
someone would have a comment on this:

What is the recommended or commonly used practice for testing EMF based
code / verification of model behavior in general?

Best regards,

Jan Capek


On Tue, 13 Oct 2009 18:03:51 +0200
Ed Merks <Ed.Merks@gmail.com> wrote:

> Jan,
>
> Comments below.
>
>
> Jan Capek wrote:
> > Hi,
> >
> > I am quite new to EMF. I have a general testing question. We use
> > EMF in conjunction with UML genmodel to generate code and test
> > code. When writing test cases for the generated classes (some
> > methods have a hand written code with business logic) we would like
> > to use mock objects (e.g. EasyMock framework or similar) so that we
> > could really unit test the objects and isolate them from the rest
> > of the model.
> I'm not familiar with that...
> > After
> > implementing a couple test cases we usually come across an issue
> > that prevents us from using a mock object/makes the mock object too
> > complex.
> >
> > Could anyone point me to any resources/docs/intro that cover these
> > topics? Does it even make sense trying to test the model like this?
> > or should the model be tested through the validation framework??
> >
> Maybe someone else is more familiar with this...
> > I have triedoogling a bit but haven't found anything related EMF +
> > JUnit + Mock or similar.
> >
> > Thank you for any input.
> >
> > Jan Capek
> >
> >
Re: testing in EMF - JUnit, Mock objects? [message #493006 is a reply to message #491200] Thu, 22 October 2009 16:30 Go to previous messageGo to next message
Cedric Brun is currently offline Cedric BrunFriend
Messages: 431
Registered: July 2009
Senior Member
Hi Jan,

We're extensively using unit testing with EMF, GMF and other modeling
technologies. Basically plain old J-Unit, SWTBot for UI stuffs, EMF compare
to detect unexpected change in a model and easymock for more complex
scenarios involving many objects.

We found easymock really convenient to test listener's like behavior and did
not encounter a specific issue so far, could you be more specific about your
problem ?


Cédric

Jan Capek wrote:

> Hi,
>
> I am quite new to EMF. I have a general testing question. We use EMF in
> conjunction with UML genmodel to generate code and test code. When
> writing test cases for the generated classes (some methods have a hand
> written code with business logic) we would like to use mock objects
> (e.g. EasyMock framework or similar) so that we could really unit test
> the objects and isolate them from the rest of the model. After
> implementing a couple test cases we usually come across an issue that
> prevents us from using a mock object/makes the mock object too complex.
>
> Could anyone point me to any resources/docs/intro that cover these
> topics? Does it even make sense trying to test the model like this? or
> should the model be tested through the validation framework??
>
> I have triedoogling a bit but haven't found anything related EMF + JUnit +
> Mock or similar.
>
> Thank you for any input.
>
> Jan Capek


http://cedric.brun.io news and articles on eclipse and eclipse modeling.
Re: testing in EMF - JUnit, Mock objects? [message #493425 is a reply to message #493006] Mon, 26 October 2009 08:20 Go to previous message
Eclipse UserFriend
Originally posted by: jan.capek.collectionspro.eu

Hi Cédric,

comments below.
> Hi Jan,
>
> We're extensively using unit testing with EMF, GMF and other modeling
> technologies. Basically plain old J-Unit, SWTBot for UI stuffs, EMF
> compare to detect unexpected change in a model and easymock for more
> complex scenarios involving many objects.
This sounds like the way we are also headed.
>
> We found easymock really convenient to test listener's like behavior
> and did not encounter a specific issue so far, could you be more
> specific about your problem ?
Basically, the issue, that we have experienced, is that it is hard to
mock an object that comes from EMF since EMF has some additional
requirements on such a mock. I will give an example - see further.

Let's say we have class A that has been generated and has method 'm()'
and this class is associated with class B. In the test case for 'm()',
we have to setup class A into a consistent state, so that it has a valid
instance of class B (substituted by a mock object).
A typical problem comes if the association is bidirectional - EMF will
try to register the opposite inside the mock. This requires that the
mock object will already be switched into testing mode eventhough we
don't want to perform the test at this point. This will be best
demonstrate by a real piece of code that I am pasting below.

I am sorry for a long and a bit confusing description. The point is
that the 'testing pattern' that we now use is that the mock objects are
operated in 2 modes - in nice mode for EMF internal operations and in
normal/strict for the actual testing resp. Essentially, the testing
with mocks is not a problem anymore once we came with this approach
that is pretty straightforward.

Would you have any suggestions from your experience how to improve this?

Regards,

Jan




Here is a code example for the JUnit setup phase - comments indicate
the critical parts:
-------------------------------------------------

protected void setUp() throws Exception {
setFixture(StatemachinesFactory.eINSTANCE.createTransition() );

mockCtl = EasyMock.createNiceControl();

mockProcess =
mockCtl.createMock(eu.collectionspro.jam.backend.processes.P rocess.class);

mockGuard = mockCtl.createMock(ITestConditionEObject.class);

/* we have to switch states of all mocks as the next few
* setter/adder calls result in reverse calls to the respective
* mock object coming from EMF.. */
mockCtl.replay();
getFixture().setCondition(mockGuard);

/* all EMF related actions have occured, we can now reset the mock
* control object back to strict, so that the rest of the test is
* precise */
mockCtl.resetToStrict();
}


The relevant test case:
-----------------------
public void testEvaluateGuard__Process() {
EasyMock.expect(mockGuard.evaluate(mockProcess)).andReturn(t rue);
mockCtl.replay();

Assert.assertTrue("Guard has evaluated as expected!",
getFixture().evaluateGuard(mockProcess));

mockCtl.verify();
}




>
>
> Cédric
>
> Jan Capek wrote:
>
> > Hi,
> >
> > I am quite new to EMF. I have a general testing question. We use
> > EMF in conjunction with UML genmodel to generate code and test
> > code. When writing test cases for the generated classes (some
> > methods have a hand written code with business logic) we would like
> > to use mock objects (e.g. EasyMock framework or similar) so that we
> > could really unit test the objects and isolate them from the rest
> > of the model. After implementing a couple test cases we usually
> > come across an issue that prevents us from using a mock
> > object/makes the mock object too complex.
> >
> > Could anyone point me to any resources/docs/intro that cover these
> > topics? Does it even make sense trying to test the model like this?
> > or should the model be tested through the validation framework??
> >
> > I have triedoogling a bit but haven't found anything related EMF +
> > JUnit + Mock or similar.
> >
> > Thank you for any input.
> >
> > Jan Capek
>
Previous Topic:difference between JET, teneo and accelero?
Next Topic:EMF for application architecture
Goto Forum:
  


Current Time: Mon Sep 23 03:24:03 GMT 2024

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

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

Back to the top