[stringtemplate-interest] template testing

Udo Borkowski ub at abego-software.de
Mon Aug 1 13:17:00 PDT 2011


> Doesn't that force you to have a group file
> per test case?

Yes, it does. 

> I was hoping to make test cases more lightweight, so a
> single template group could define dozens of them
> (actual_foo/expected_foo, actual_bar/expected_bar, etc), ie, a
> template group would define a test suite instead of a test case.

Should not be a big deal, I guess. Just define a naming convention you stick to and multiple "tests" per group are no issue. 

In my case one test per group is fine as I am not doing small "unit tests". My "main_expected" templates are (most of the time) 'raw' texts given by the client and the texts can be quite large. My task is to create a template ("main") that generates exactly the same result as the given text. Typically this mean the main template is composed of many other "sub templates" also contained in the same group.

Udo


On 01.08.2011, at 21:59, Rafael Chaves wrote:

> Thanks, Udo, similar idea. Doesn't that force you to have a group file
> per test case? I was hoping to make test cases more lightweight, so a
> single template group could define dozens of them
> (actual_foo/expected_foo, actual_bar/expected_bar, etc), ie, a
> template group would define a test suite instead of a test case.
> 
> Cheers,
> 
> Rafael
> 
> On Mon, Aug 1, 2011 at 12:51 PM, Udo Borkowski <ub at abego-software.de> wrote:
>>> Basically, what I am thinking of is to conventionally use two
>>> templates to represent a test case: one defines the expected output,
>>> and another defines the actual output (by applying the template to be
>>> tested to some parameters). The test runner basically renders each
>>> pair of templates and compares the outputs - if they match, it is a
>>> pass, if they don't, it is a failure (maybe if only spaces differ,
>>> make it a warning).
>> 
>> I am using this approach for my development:
>> 
>> the template "main" in a string group is evaluated and compared against the result of template "main_expected" in the same group.
>> If both differ I can view the difference in a "Diff viewer".
>> 
>> Udo
>> 
>> 
>> On 01.08.2011, at 21:14, Rafael Chaves wrote:
>> 
>>> We adopted StringTemplate in a MDD tool we are developing where users
>>> can customize code generation by editing their templates. I really
>>> miss an easy way to test the templates. Is there anything out there
>>> for this? (If not, we will be rolling our own)
>>> 
>>> Basically, what I am thinking of is to conventionally use two
>>> templates to represent a test case: one defines the expected output,
>>> and another defines the actual output (by applying the template to be
>>> tested to some parameters). The test runner basically renders each
>>> pair of templates and compares the outputs - if they match, it is a
>>> pass, if they don't, it is a failure (maybe if only spaces differ,
>>> make it a warning).
>>> 
>>> Has anyone seen anything like that?
>>> 
>>> Cheers,
>>> 
>>> Rafael
>>> http://alphasimple.com
>>> _______________________________________________
>>> stringtemplate-interest mailing list
>>> stringtemplate-interest at antlr.org
>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>> 
>> 



More information about the stringtemplate-interest mailing list