leetcode插件模板,网上很多都 是直接添加 Main函数的,但是并不能使用junit做一些测试,只能跑一下main函数的方式,其实只需要修改一下即可。
如我的配置,
codeFileName:
P${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})
code Tempalte: ${question.content}
package leetcode.editor.cn;
CodeTempate:
//Java:${question.title}
public class P${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug}){
@Test
public void testP${question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})() {
Solution solution = new P$!{question.frontendQuestionId}$!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
}
${question.code}
}
TempateConstant:
${question.title} 题目标题 示例:两数之和
${question.titleSlug} 题目标记 示例:two-sum
${question.frontendQuestionId} 题目编号
${question.content} 题目描述
${question.code} 题目代码
$!velocityTool.camelCaseName(str) 转换字符为驼峰样式
$!velocityTool.snakeCaseName(str) 转换字符为蛇形样式
$!velocityTool.leftPadZeros(str,n) pad sting with zero make str length at least n.
$!velocityTool.date() 获取当前时间
同时Idea设置自动导入类,最后只需要双击题号,就可以生成下面的模板,写好测试用例,就可以愉快的coding了
最终效果如下: