如何创建SpringBoot代码测试类

 时间:2024-10-15 00:08:04

1、从实际的项目角度来讲,必须要求考虑到代码的测试问题,而且现在的程序代码属于SpringBoot,需要在你的项目之中进行如下的pom.xml文件修改:

如何创建SpringBoot代码测试类

3、只要进行java测试,最简单使用的就是junit,所以这个开发包一定要将测试进行导入。

如何创建SpringBoot代码测试类

5、在TestSampleController类中增加测试类注解。package org.microboot.bas髫潋啜缅e;import javax.annotation.Resource;import junit.framework.TestCase;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import org.springframework.test.context.web.WebAppConfiguration;@RunWith(SpringJUnit4ClassRunner.class)@SpringBootTest(classes=SampleController.class)@WebAppConfigurationpublic class TestSampleController { @Resource private SampleController sampleController; @Test public void testHome() { TestCase.assertEquals(this.sampleController.home(), "Hello World!"); }}

如何创建SpringBoot代码测试类
  • JavaWeb登录页面的开发
  • eclipse中使用DatabaseExplorer连接MySQL数据库
  • 如何使用jquery实现淡入淡出效果
  • tomcat源码编译并导入eclipse运行
  • java中printf、println、print的区别
  • 热门搜索
    旅游毕业论文 雅加达旅游攻略 板门店旅游 湖南郴州旅游 3月份适合去哪里旅游 全景旅游 旅游局网站 湖北省旅游局官网 涞源旅游 去美国旅游要多少钱