基于模板的代码生成器的单元测试
TUnit - Unit Testing For Template-based Code Generators
摘要:
基于模板的代码生成器开发作为模型驱动开发(MDD)的一部分,需要强大的机制和工具来支持开发人员提高健壮性,即,为指定的输入生成期望的代码。尽管已经提出了不同的测试方法,但是仍然缺乏一种方法,该方法仅测试基于模板的代码生成器的一部分,并且可以在开发的早期阶段使用。因此,在本文中,我们提出了一种方法和基于JUnit的测试基于模板的代码生成器的实现。它不是测试一个完整的代码生成器,而是通过模拟环境支持模板的执行来简化部分测试。这简化了在开发的早期阶段对代码生成器的测试以及对代码生成器的新部件或更改部件的测试。为了测试由被测模板生成的源代码,提出了不同的方法,包括字符串比较,基于API的断言,和基于抽象语法树的断言。
英文摘要:
Template-based code generator development as part of model-drivendevelopment (MDD) demands for strong mechanisms and tools that support developers to improve robustness, i.e., the desired code is generated for the specified inputs. Although different testing methods have been proposed,a method for testing only parts of template-based code generators that can be employed in the early stage of development is lacking. Thus, in this paper we present an approach and an implementation based on JUnit to test template-based code generators. Rather than testing a complete code generator,it facilitates partial testing by supporting the execution of templates with a mocked environment. This eases testing of code generators in early stages of development as well as testing new orchanged parts of a code generator. To test the source code generated by the templates under test, different methods are presented including string comparisons, API-based assertions, and abstract syntax tree based assertions.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。