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

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

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!"); }}
