Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » UnitTest for custom tags
UnitTest for custom tags [message #41073] Fri, 25 January 2008 16:41 Go to next message
Eclipse UserFriend
Originally posted by: pankaj.surti.accenture.com

I show the following code for unit testing LoadTag.
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/tests/org.eclipse.jet.tests/src/org/eclipse/jet /tests/taglib/control/LoadTagTests.java?root=Modeling_Projec t&view=log

My question is, how to do the unit test for my Iterating custom tag?


Thanks in advance.
- Pankaj,
Re: UnitTest for custom tags [message #41197 is a reply to message #41073] Thu, 31 January 2008 16:10 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Pankaj:

Two ideas.

1) Quick and dirty. Create a Small JET transformation that uses your tag
against a model, and then compare the output with the output you expect.

2) Do a real JUnit by creating test that instantiates your iterating Tag,
and then calls all the methods described in the Javadoc in the order they
are supposed to be called.

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. jet.doc/references/javadoc/org/eclipse/jet/taglib/IteratingT ag.html

The methods generally take TagInfo, JET2Context and JET2Writer objects.
* TagInfo's are easy to contruct, they just describe a tag instance and most
importantly, include the attribute values for the tag instance.
* JET2Context is the wrapper for your input model. Get your test input model
into memory, and pass it to the JET2Context. For EMF models, pass an EMF
Resource instance. For XML documents, pass a w3 Document instance. Whatever
you pass will be treated as '/' by the XPath engine. You can pass other
objects to the context, but adjust your tag expression as appropriate. Also,
you can define XPath variables in the context - this may be as useful as
setting a 'source' in the context.
* JET2Writer - instantiate a BodyContentWriter. After you tests, call
getContent() to return the text written by the JUnits.

It may be best to do both approaches. Approach 2 is very white box, and will
be prone to mistakes in understanding invoking the tag protocol, but it does
eliminate a lot of other noise. Approach 1 tests the tag in its actual
execution context.

Paul

"pankaj" <pankaj.surti@accenture.com> wrote in message
news:62a34ed7a5ac247bfd50814876772c61$1@www.eclipse.org...
>
> I show the following code for unit testing LoadTag.
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/tests/org.eclipse.jet.tests/src/org/eclipse/jet /tests/taglib/control/LoadTagTests.java?root=Modeling_Projec t&view=log
>
> My question is, how to do the unit test for my Iterating custom tag?
>
>
> Thanks in advance.
> - Pankaj,
>
Previous Topic:minimal jet plugin
Next Topic:ANT Task for JET
Goto Forum:
  


Current Time: Thu Apr 25 20:51:23 GMT 2024

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

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

Back to the top