Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.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.value}};
{% endfor %}
{#{{test.returnType}} {{test.returnInstance}} {{test.assign}} {{tc.serviceInstance}}.{{test.method}}({{test.paramsInit}});#}
{% 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
You can’t perform that action at this time.