引入相关依赖
<!--springboot程序测试依赖,如果是自动创建项目默认添加--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
搞一个测试类
import com.example.demo.AndroidApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) //底层用junit SpringJUnit4ClassRunner
@SpringBootTest(classes={AndroidApplication.class})//启动整个springboot工程
public class Mytest {
@Test
public void test1(){
System.out.println("你好,这里是测试方法");
}
}
常用单元测试的注解
@before
@Test
@After
本文作者为DBC,转载请注明。