码迷,mamicode.com
首页 > 编程语言 > 详细

springBoot测试

时间:2019-08-05 15:37:22      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:factory   ati   unit   factor   junit4   config   port   开发   org   

1.SpringBoot开发框架里提供有“spring-test”测试程序依赖只需要导入依赖库即可

 1         <dependency>
 2             <groupId>junit</groupId>
 3             <artifactId>junit</artifactId>
 4             <scope>test</scope>
 5         </dependency>
 6         <dependency>
 7             <groupId>org.springframework.boot</groupId>
 8             <artifactId>spring-boot-starter-test</artifactId>
 9             <scope>test</scope>
10         </dependency>

2.测试程序,同样要注意注解

 1 package com.lion.test;
 2 import com.lion.StartBootMain;
 3 import com.lion.action.MessageAction;
 4 import org.junit.Test;
 5 import org.junit.runner.RunWith;
 6 import org.springframework.beans.factory.annotation.Autowired;
 7 import org.springframework.boot.test.context.SpringBootTest;
 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 9 import org.springframework.test.context.web.WebAppConfiguration;
10 @RunWith(SpringJUnit4ClassRunner.class)
11 @WebAppConfiguration
12 @SpringBootTest(classes = StartBootMain.class)
13 public class MessageActionTest {
14     @Autowired
15     private MessageAction messageAction ;
16     @Test
17     public void testEcho() {
18         System.out.println(messageAction.echo());
19     }
20 }

 

springBoot测试

标签:factory   ati   unit   factor   junit4   config   port   开发   org   

原文地址:https://www.cnblogs.com/fcitx/p/11303223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!