一、单元测试
1.基础版
1、引入相关依赖
<!--springboot程序测试依赖,如果是自动创建项目默认添加-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2:关键注解:@RunWith @SpringBootTest
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
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={SpringbootstudyApplication.class})//启动整个springboot工程
public class SpringBootTestDemo {
@Test
public void testOne(){
System.out.println("test hello 1");
TestCase.assertEquals(1, 1);
}
@Test
public void testTwo(){
System.out.println("test hello 2");
TestCase.assertEquals(1, 1);
}
@Before
public void testBefore(){
System.out.println("before");
}