To be honest, I've been moving away from testing the actual code generation towards your later observation, the create the class with the enhanced code and see that it works.
To me that's a general maxum: with code generation, testing the generated source isn't useful, testing the generated compiled class is. A unit test could be useful for testing various method or field matching logic, and error logic. But an integration test (either relatively contained, such as creating the EnhancementOperationImpl, or wider, such as firing up the app and testing with selenimum) is the only worthwhile way to ensure that generated code is correct. On 6/4/07, carlos f <[EMAIL PROTECTED]> wrote:
I have written an enhancement worker that adds some conditional logic to a component. The unit tests I have written rely on mock objects to verify the behavior under test is appropriate. This is similar to the design of the unit tests in the tapestry-framework project. look at testStandard() as a reference -- http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/enhance/TestParameterPropertyWorker.java?revision=419064&view=markup The most critical method mocked is the EnchancementOperation.addMethod() method - among the various arguments addMethod() expects, is a string that represents the body of the method added. My mock, basically tests that the string argument used in the implementation is a character for character match of the "expected" method body. My unit tests do not guarantee that the actual method body will behave as expected . . . it may even throw a litany of exceptions at runtime. In order to test a component that has been enhanced by my class under test, requires newing up an EnhancementOperationImpl and generating the ComponentSpecification. Doing this seems to involve a number of framework classes - it may be significantly more work than it is worth at this point. Has anyone done this before for testing enhancement workers? Carlos -- View this message in context: http://www.nabble.com/Unit-Testing-EnhancementWorkers-tf3867100.html#a10955775 Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Howard M. Lewis Ship TWD Consulting, Inc. Independent J2EE / Open-Source Java Consultant Creator and PMC Chair, Apache Tapestry Creator, Apache HiveMind Professional Tapestry training, mentoring, support and project work. http://howardlewisship.com