maven依赖 pom.xml:
<!-- unit test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.6.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.6.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<!-- unit test end -->
java类单元测试例子:
@RunWith(SpringRunner.class)
@SpringBootTest
@Service
public class ModTestService extends AbstractBillService/*<ModReceive> implements IModTestService*/ {
@org.junit.Test
@Commit //如果有涉及数据提交的,要加上这个注解
public void test() {
....
}
}