Skip to content

Instantly share code, notes, and snippets.

@dylanninin
Created November 12, 2013 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanninin/7426041 to your computer and use it in GitHub Desktop.
Save dylanninin/7426041 to your computer and use it in GitHub Desktop.
A Jinja2 template for rendering source code of jUnit testcase in Java web applications, especially for interfaces. It just shows the basic design, you can impletement it better with Python or Java, either is good.
package {{tc.toPackage}};
{% for import in tc.imports %}
import {{import}};{% endfor %}
/**
* {{tc.testCase}}.java
* {{tc.comment.abstract}}:
* TestCase (JUnit) for {{tc.service}}
* {{tc.comment.history}}
* {{tc.comment.date}} {{tc.comment.author}} {{tc.comment.content}}
*/
public class {{tc.testCase}} extends {{tc.superTestCase}} {{'{'}}
private {{tc.service}} {{tc.serviceInstance}} = ({{tc.service}}) ctx.getBean("{{tc.serviceBean}}");
{% for test in tc.tests %}
/**
* test method {{test.method}}
*/
public void {{test.test}}() {{test.throw}} {{'{'}}
//JUnit Add your test implementation here
{% for param in test.params %}{{param.type}} {{param.name}} = {{param.value}};
{% endfor %}
{#{{test.returnType}} {{test.returnInstance}} {{test.assign}} {{tc.serviceInstance}}.{{test.method}}({{test.paramsInit}});#}
{{test.call}}
{% for assert in test.asserts %}{{assert}}
{% endfor %}
{{'}'}}
{% endfor %}
{{'}'}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment