Code Generation and Testing
For my day job I specialize in writing automated API tests for an SDK (Software Development Kit). The SDK consists of ActiveX components. That means our customers can write application using either C++, C#, JavaScript or even Java. To test that in all supported languages - even a single language - I need to generate a lot of code. It can be a maintenance nightmare. To make my life easier I turned to code generation.
Code generation is too complicated to explain in a blog posting. So I may write an eBook on the subject as it relates to testing at some point. Until then a great place to start is the book Code Generation in Action by Jack Herrington.
There is no set way on how to implement code generation. It's a matter of personal preference. You can write your own template language and parser. What I decided to do was encode my test cases in XML using a pseudo language customized for the SDK. Then I use XSLT to transform the XML into source files (*.js, *.cs, etc.).
I write all of my test cases in Eclipse using Ant to drive the transformation. It's worked out quite well (except for Ant throwing Java heap errors now and then). In the old days I had to cut and paste test case functions into huge source files that were quite easy to mangle and get lost in. Now I don't write one line of code in a traditional software language. I write one test case per XML file and let the computer generate the source code for me.
Code generation is too complicated to explain in a blog posting. So I may write an eBook on the subject as it relates to testing at some point. Until then a great place to start is the book Code Generation in Action by Jack Herrington.There is no set way on how to implement code generation. It's a matter of personal preference. You can write your own template language and parser. What I decided to do was encode my test cases in XML using a pseudo language customized for the SDK. Then I use XSLT to transform the XML into source files (*.js, *.cs, etc.).
I write all of my test cases in Eclipse using Ant to drive the transformation. It's worked out quite well (except for Ant throwing Java heap errors now and then). In the old days I had to cut and paste test case functions into huge source files that were quite easy to mangle and get lost in. Now I don't write one line of code in a traditional software language. I write one test case per XML file and let the computer generate the source code for me.
Labels: code generation, software quality assurance, sqa, test
0 Comments:
Post a Comment
<< Home