[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-242888-105":53,"doc-detail-242888-en":118},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":111,"head_meta":113,"extra_data":115,"updated_unix":117},105,"en","tunit-unit-testing-for-template-based-code-generators","TUnit - Unit Testing For Template-based Code Generators","","Template-based code generator development within model-driven development (MDD) requires strong mechanisms to ensure robustness: the generated code must match specified inputs. While multiple testing methods exist, early-stage testing for only parts of template-based code generators is insufficient. This paper presents an approach and a JUnit-based implementation (TUnit) enabling partial testing via mocked execution contexts. It supports validating generated source code using string comparisons, API-based assertions, and abstract syntax tree assertions.",{"@graph":63,"@context":110},[64,80,101],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":11,"@type":70,"position":76},"https://docshare.wps.com/template/presentations/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/tunit-unit-testing-for-template-based-code-generators/242888/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/tunit-unit-testing-for-template-based-code-generators/242888.png","ImageObject",442,249,{"name":88,"@type":89},"Đào","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-19","2026-09-12",true,{"@type":98,"interactionType":99,"userInteractionCount":76},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104],{"name":105,"@type":106,"acceptedAnswer":107},"Why are string comparisons insufficient in TUnit?","Question",{"text":108,"@type":109},"String comparisons are prone to changes that do not affect semantics, such as added, removed, or reordered whitespace, making tests less robust in evolving templates.","Answer","https://schema.org",{"og:url":78,"og:type":112,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":114,"canonical":78},"index,follow",{"doc_id":116,"site_id":56},242888,1792019717,{"code":4,"msg":5,"data":119},{"doc_id":116,"user_id":120,"nickname":88,"user_avatar":121,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":122,"file_id":123,"file_url":124,"file_type":125,"file_size":126,"view_count":76,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":30,"language":127,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":128,"faqs":129,"seo_title":130,"seo_description":61,"update_tm":131,"read_time":132},1374402968488,"https://ap-avatar.wpscdn.com/davatar_29158cc5080c5b710cf443261637dec0","TUnit – Unit Testing For Template-based Code Generators  \nCarsten Kolassa1 Markus Look 1, Klaus M¨uller 1, Alexander Roth1, Dirk Reiß2 , Bernhard Rumpe 1  \nAbstract: Template-based code generator development as part of model-driven development (MDD) demands for strong mechanisms and tools that support developers to improve robustness, i.e., the desired code is generated for the speciﬁed 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 or changed 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.  \nKeywords: Model-Driven Development; Partial Code Generator Testing; Template-based Code Generation  \n1 Introduction  \nWith the increasing adoption of model-driven development (MDD) in research and industry [Hu11, Li14], code generation-systematic transformation of compact models to detailed code [FR07] - is gaining importance. To support code generator developers in constructing robust code generators, i.e., code generators that produce the desired code for the speciﬁed input, sophisticated mechanisms and tools are required. They have to beintegrable into the development process and especially for agile development processes they need to enable partial testing of code generators. Such testing as an essential activity is, however, challenging [St07] .  \nCurrent approaches for testing code generators (cf. [St07, J¨o13, SWC05, Ra10, St06]) require an initial integration effort of the testing procedure, are based on string comparisons only, or are designed to test the code generator as a whole. Other code generator testing approaches employ formal methods [BKS04] . Setting up such tests is time-consuming and once set up they are hard to maintain in an evolving environment, because small changes in the code generator may lead to larger changes in the tests. Consequently, existing testing approaches for code generators are not so easy to use in an agile development environment, where either the code generator does not yet generate complete code artifacts that the tests can validate or only the increment in functionality is to be tested. In summary, exisiting work lacks approaches for partial code generator testing.  \n1 RWTH Aachen University, Software Engineering, Germany, [http://www.se-rwth.de](http://www.se-rwth.de)  \n2 TU Braunschweig, Institute for Building Services and Energy Design, Germany  \nFocusing on template-based code generation, the goal of this paper is to present an approach for testing individual components of template-based code generators that can be employed in early development stage of code generators. We introduce TUnit, an extension of JUnit [JU15] based on the MontiCore [KRV10, Gr08, KRV08] language workbench to support unit testing of code generator templates. In our case, testing a code generator or parts of it means to answer the following questions: Is the set of speciﬁed inputs accepted by the code generator template, e.g., code is generated? Does the code generator template produce syntactically valid source code? Are the target language context conditions valid for the generated source code? Executing a TUnit test case will run the template under test with a mocked context (e.g. mocked variables, mocked templates, or mocked helper functionality) on (parts of) an input model. This approach allows for testing the output of a single template under test ","cbCaisduj3vMGNe4","https://ap.wps.com/l/cbCaisduj3vMGNe4","pdf",357959,"English","# Abstract\n## Introduction\n## Related Work\n## TUnit Approach\n## Contributions\n## Paper Structure","[{\"question\":\"Why are string comparisons insufficient in TUnit?\",\"answer\":\"String comparisons are prone to changes that do not affect semantics, such as added, removed, or reordered whitespace, making tests less robust in evolving templates.\"}]","TUnit - Unit Testing For Template-based Code Generators | PDF",1789196576,6]