Leetcode测试类模板
POM文件:
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit-jupiter.version>5.9.0</junit-jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
settings > Editor > File and Code Templates,复制一份class,命名为leetcode,修改内容如下,新建文件时选择leetcode比如输入104MaxDepth就可以新建一个名为LeetCode104MaxDepth的类,并且包含了基本的测试模板,只用配好多个测试用例,就可以轻松测试调试了。
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.List;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
public class LeetCode${NAME}Test
{
private static class Input
{
}
@SuppressWarnings("unused")
private static List<Input> createInput()
{
List<Input> inputs = new ArrayList<>();
Input input;
input = new Input();
inputs.add(input);
return inputs;
}
@ParameterizedTest
@MethodSource("createInput")
public void test(Input in)
{}
}
博客介绍了Leetcode测试类模板,通过复制文件、命名并修改内容,新建文件时选择特定输入可创建包含基本测试模板的类,配好多个测试用例就能轻松进行测试调试。
3704

被折叠的 条评论
为什么被折叠?



