Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Advices for unit testing ?
[Acceleo] Advices for unit testing ? [message #495299] Wed, 04 November 2009 14:23 Go to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
In the scope of my code generation project, I would like to perform automated unitary tests of the transformation results.
Does anyone has already experienced unit testing with M2T ?

What is the best way to perform that ?

Thank you for your answers

Sebastien
Re: [Acceleo] Advices for unit testing ? [message #495523 is a reply to message #495299] Thu, 05 November 2009 08:34 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000502090709050006060101
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Sebastien,

We've never really unit tested the templates themselves, yet you can
take a look at the Acceleo unit tests for what we do to compare the
generation results and make sure it does not evolve/change between two
versions.

Laurent Goubet
Obeo

S a écrit :
> In the scope of my code generation project, I would like to perform
> automated unitary tests of the transformation results.
> Does anyone has already experienced unit testing with M2T ?
>
> What is the best way to perform that ?
>
> Thank you for your answers
>
> Sebastien
>


--------------000502090709050006060101
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------000502090709050006060101--
Re: [Acceleo] Advices for unit testing ? [message #495602 is a reply to message #495299] Thu, 05 November 2009 13:41 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
I usually recommend to write tests against the generated code.
This is far more robust compared to just comparing the text between two
versions of the generator.

Cheers,
Sven


S schrieb:
> In the scope of my code generation project, I would like to perform
> automated unitary tests of the transformation results.
> Does anyone has already experienced unit testing with M2T ?
>
> What is the best way to perform that ?
>
> Thank you for your answers
>
> Sebastien
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: [Acceleo] Advices for unit testing ? [message #495607 is a reply to message #495602] Thu, 05 November 2009 12:48 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020800050100050502040204
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Sven,

This is only possible when what you generate is code, though Acceleo is
a text generator. Granted, when the target is code, the best bet is to
write unit tests against the target. Yet when the target is XML ...

Laurent Goubet
Obeo

Sven Efftinge wrote:
> I usually recommend to write tests against the generated code.
> This is far more robust compared to just comparing the text between two
> versions of the generator.
>
> Cheers,
> Sven
>
>
> S schrieb:
>> In the scope of my code generation project, I would like to perform
>> automated unitary tests of the transformation results.
>> Does anyone has already experienced unit testing with M2T ?
>>
>> What is the best way to perform that ?
>>
>> Thank you for your answers
>>
>> Sebastien
>>
>
>


--------------020800050100050502040204
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------020800050100050502040204--
Re: [Acceleo] Advices for unit testing ? [message #670923 is a reply to message #495602] Mon, 16 May 2011 08:22 Go to previous messageGo to next message
Gregoire Dupe is currently offline Gregoire DupeFriend
Messages: 75
Registered: September 2009
Location: France
Member
Hello,

Is there any news about the unit test of templates?

I have developed a unit test to check one of my generators, but when I break my generator the unit test does not failed. No exception is thrown but I can find message in the log.

I use the following line to launch the generator :
new HtmlReport(benchmark, targetDirectory, new ArrayList<Object>()).doGenerate(null);

How should I call my generator to be able to get an exception when my generator fails? To be able to get those exceptions would be really use full to develop low cost unit tests.

I get such kind of Exception :

!ENTRY org.eclipse.ocl 4 10 2011-05-13 19:27:57.956
!MESSAGE Evaluation failed with an exception: index: 0, size: 10
!STACK 0
java.lang.IndexOutOfBoundsException: index: 0, size: 10
at org.eclipse.ocl.util.CollectionUtil.at(CollectionUtil.java:8 86)
at org.eclipse.ocl.EvaluationVisitorImpl.visitOperationCallExp( EvaluationVisitorImpl.java:1213)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitOperationCallExp(AcceleoEvaluationVisitor.j ava:1064)
at org.eclipse.ocl.ecore.impl.OperationCallExpImpl.accept(Opera tionCallExpImpl.java:390)
at org.eclipse.ocl.EvaluationVisitorImpl.visitPropertyCallExp(E valuationVisitorImpl.java:2061)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitPropertyCallExp(AcceleoEvaluationVisitor.ja va:1075)
at org.eclipse.ocl.ecore.impl.PropertyCallExpImpl.accept(Proper tyCallExpImpl.java:238)
at org.eclipse.ocl.AbstractEvaluationVisitor.visitExpression(Ab stractEvaluationVisitor.java:248)
at org.eclipse.ocl.EvaluationVisitorDecorator.visitExpression(E valuationVisitorDecorator.java:156)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.switchExpression(AcceleoEvaluationVisitor.java:1 650)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitExpression(AcceleoEvaluationVisitor.java:96 3)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitAcceleoForBlock(AcceleoEvaluationVisitor.ja va:402)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.switchExpression(AcceleoEvaluationVisitor.java:1 613)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitExpression(AcceleoEvaluationVisitor.java:96 3)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitAcceleoFileBlock(AcceleoEvaluationVisitor.j ava:386)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.switchExpression(AcceleoEvaluationVisitor.java:1 620)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitExpression(AcceleoEvaluationVisitor.java:96 3)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.ja va:832)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.switchExpression(AcceleoEvaluationVisitor.java:1 600)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvalua tionVisitor.visitExpression(AcceleoEvaluationVisitor.java:96 3)
at org.eclipse.ocl.internal.evaluation.QueryImpl.evaluate(Query Impl.java:152)
at org.eclipse.ocl.ecore.QueryImpl.evaluate(QueryImpl.java:62)
at org.eclipse.acceleo.engine.generation.AcceleoEngine.doEvalua te(AcceleoEngine.java:265)
at org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate (AcceleoEngine.java:130)
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate Template(AcceleoService.java:765)
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate (AcceleoService.java:478)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator. generate(AbstractAcceleoGenerator.java:175)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator. doGenerate(AbstractAcceleoGenerator.java:154)
at org.eclipse.modisco.java.discoverer.benchmark.template.html. HtmlReport.doGenerate(HtmlReport.java:195)
at org.eclipse.modisco.java.discoverer.benchmark.Report.generat eHTML(Report.java:324)
at org.eclipse.modisco.java.discoverer.benchmark.Report.generat e(Report.java:102)
at org.eclipse.modisco.java.discoverer.benchmark.RunBenchmark.c reateReport(RunBenchmark.java:44)
at org.eclipse.modisco.java.discoverer.benchmark.tests.JavaDisc overerBenchmarkTest.test001(JavaDiscovererBenchmarkTest.java :50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at org.junit.internal.runners.statements.FailOnTimeout$1.run(Fa ilOnTimeout.java:28)

!ENTRY org.eclipse.acceleo.engine 2 2 2011-05-13 19:27:57.956
!MESSAGE Invalid loop iteration at line 49 in Module htmlReport for block for (b.projects->at(0).discoveries). Last recorded value of self was org.eclipse.modisco.infra.discovery.benchmark.impl.MultiProj ectBenchmarkImpl @8966e9 (jvmMaxHeapInMiB: 0, processorName: null, processorDescription: null, processorCount: 0, processorCacheSize: null, systemMemory: null, osName: null, osVersion: null, osArchitecture: null).
!STACK 0
org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid loop iteration at line 49 in Module htmlReport for block for (b.projects->at(0).discoveries). Last recorded value of self was org.eclipse.modisco.infra.discovery.benchmark.impl.MultiProj ectBenchmarkImpl @8966e9 (jvmMaxHeapInMiB: 0, processorName: null, processorDescription: null, processorCount: 0, processorCacheSize: null, systemMemory: null, osName: null, osVersion: null, osArchitecture: null).
at htmlReport.htmlReport(MultiProjectBenchmark)(htmlReport.mtl: 49)
at htmlReport.htmlReport(MultiProjectBenchmark)(htmlReport.mtl: 17)
at htmlReport.htmlReport(MultiProjectBenchmark)(htmlReport.mtl: 14)
Re: [Acceleo] Advices for unit testing ? [message #671245 is a reply to message #670923] Tue, 17 May 2011 09:21 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,
The problems found by Acceleo are logged using the standard logging mechanism in Eclipse and they appear in the error log.
You can find here some documentation in order to listen to the errors logged by a specific eclipse plugin or by the complete Eclipse platform. Something like org.eclipse.acceleo.engine.AcceleoEnginePlugin.getLog().addL ogListener(...) and org.eclipse.acceleo.common.AcceleoCommonPlugin.getLog().addL ogListener(...) should do the trick if you want to listen to errors from the generation.

Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Re: [Acceleo] Advices for unit testing ? [message #671324 is a reply to message #671245] Tue, 17 May 2011 14:15 Go to previous messageGo to next message
Gregoire Dupe is currently offline Gregoire DupeFriend
Messages: 75
Registered: September 2009
Location: France
Member
Hello,

Thank you for your advice. It solve my problem.

Here is the patch to listen to the log of the Acceleo engine : https://bugs.eclipse.org/bugs/attachment.cgi?id=195859

Regards,
Gregoire Dupe
Re: [Acceleo] Advices for unit testing ? [message #671582 is a reply to message #671324] Wed, 18 May 2011 11:54 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

"but when I break my generator the unit test does not failed"

If you want to detect errors during the parsing of your generator, you may want to look at the test project org.eclipse.acceleo.parser.tests.
This utility class used for our test may help you. You can see how we are using it here.

We are checking for informations, warnings and errors during each steps of the compilation, like this:
checkCSTParsing(moduleFile, 0, 0, 0);
checkCST2ASTConvertion(1, 0, 0);
checkASTResolution(1, 0, 0);
checkASTDocumentationResolution(1, 0, 0);


You woudln't have to launch the generation for that.

Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com

Previous Topic:[Acceleo] Bug in Acceleo ?
Next Topic:XPand Multiplicity
Goto Forum:
  


Current Time: Thu Apr 25 00:41:05 GMT 2024

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

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

Back to the top