|
Re: UnitTest for custom tags [message #41197 is a reply to message #41073] |
Thu, 31 January 2008 11:10  |
Eclipse User |
|
|
|
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,
>
|
|
|
Powered by
FUDForum. Page generated in 0.02804 seconds