引入依赖
1 2 3 4 5
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
|
测试类
1 2 3 4 5 6 7
| @Service public class TestService { public void hello() { System.out.println("hello"); } }
|
测试
在src/test/java目录下创建一个和启动类同目录的测试类。
如果不在同目录,需要通过classes属性指定启动类
1 2 3 4 5 6 7 8 9 10 11 12 13
| @SpringBootTest(classes = MyApplication.class)
public class MyTests {
@Autowired TestService testService;
@Test public void test(){ testService.hello(); } }
|