Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Junit eunit example - test with resource models
Junit eunit example - test with resource models [message #1838938] Tue, 09 March 2021 21:53 Go to next message
Kieran Thompson is currently offline Kieran ThompsonFriend
Messages: 7
Registered: January 2021
Junior Member
Hello,

I am currently working on top of a version the junit eunit example, from the repo. I wondering the best way to test models that have been imported in. The models in the resources folder being used in the eunit. How can these be called in the eunit file so they can be compared/altered?

edit: My understanding is the base example runs a tranformation on a model and then compares with an expected model. Please correct me if I am incorrect in thinking this.


Kind regards
Kieran

[Updated on: Wed, 10 March 2021 01:45]

Report message to a moderator

Re: Junit eunit example - test with resource models [message #1838950 is a reply to message #1838938] Wed, 10 March 2021 09:00 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Yes, the eunit.junit example runs an ETL transformation and then makes some checks on the resulting model. In fact, it uses the assertEqualModels assertion to compare that the models are equal according to EMF Compare. In order to make these models available to the assertEqualModels assertion, they have to be loaded into the model repository. While there is a resources/models/graph-expected.model file in the example, this file is not really used: the current version of the example just has GraphExpected start empty, and populates the expected contents right in the test to save time.

You could modify the prepareModels method in JUnitIntegrationExampleSuite to have it load a different set of models and have them really load their contents from the files, and then you could use assertEqualModels to check that the transformation results match those loaded models.

Hope that clarifies things - let me know if you have more questions!
Re: Junit eunit example - test with resource models [message #1838970 is a reply to message #1838950] Wed, 10 March 2021 16:06 Go to previous messageGo to next message
Kieran Thompson is currently offline Kieran ThompsonFriend
Messages: 7
Registered: January 2021
Junior Member
Thank you for your help , that does help me.

I am currently finding it difficult to import those defined models and using them in the test. I have tried to create a new function to import the models, similiar to loadEmptyModel, being called in the prepareModels, this does not seem to import the model. Is there an example of doing this in the repo that I have missed?

Kind regards
Kieran

Re: Junit eunit example - test with resource models [message #1839081 is a reply to message #1838970] Fri, 12 March 2021 15:34 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

In order to actually load the contents of the file, you need to call setReadOnLoad(true) on the EmfModel, and then also make sure that the EmfModel gets added to the list returned by prepareModels(). Have you checked that you are doing both things?

Here is another example which compares JUnit and straight-up EUnit for testing an ETL transformation:

https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.eunit.examples.etl

Specifically, there is a loadModel function that loads a model:

https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.eunit.examples.etl/src/org/eclipse/epsilon/eunit/examples/etl/vsjunit/TransformationTest.java#n105
Re: Junit eunit example - test with resource models [message #1839108 is a reply to message #1839081] Sun, 14 March 2021 14:20 Go to previous messageGo to next message
Kieran Thompson is currently offline Kieran ThompsonFriend
Messages: 7
Registered: January 2021
Junior Member
Thank you for your help with that. I have got it work now.

Thanks again.
Re: Junit eunit example - test with resource models [message #1839566 is a reply to message #1839081] Wed, 24 March 2021 00:29 Go to previous messageGo to next message
Kieran Thompson is currently offline Kieran ThompsonFriend
Messages: 7
Registered: January 2021
Junior Member
Hello

I am currently seeing a loaded model in the tests if it is called within assertEqualModels("modelname", ...).

How do I get to set a model to a variable in the tests, eg var t = "modelname" ?
Currently I can not get this to work despite the model being loaded in the same way as the other model in the assertEqualModels.

Thank you for your help with this
Kieran
Re: Junit eunit example - test with resource models [message #1839722 is a reply to message #1839566] Fri, 26 March 2021 13:50 Go to previous message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

I'm not sure I understand the issue. Could you post a minimal working example that reproduces your problem?

assertEqualModels just takes the names of two models in your model repository - it does not matter whether you use literal strings, variables, or other expressions to compute those names.
Previous Topic:Load Hutn file programmatically
Next Topic:Suppressing or Redirecting Stacktraces from Workflow
Goto Forum:
  


Current Time: Sat Apr 27 13:12:55 GMT 2024

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

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

Back to the top