- pom文件加依赖:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version> <!-- 版本号可替换为最新版本 -->
<scope>test</scope>
</dependency>
- 测试代码块使用Junit,Junit约定在测试方法上加@Test注解,不需要在Class上面加注解。
import org.junit.Test;
import static org.junit.Assert.*;
public class YourClassTest {
@Test
public void testSomeMethod() {
// 测试逻辑
assertEquals(expectedValue, actualValue);
}
// 添加更多的测试方法
}