/**
* 测试类基类-测试总入口
*/
package lianxi;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class TestPortal {
@Before
public void init(){
System.out.println("---start test---");
}
@After
public void after() {
System.out.println("---end test---");
}
}
SECOND
/**
* 具体测试-继承基类
*/
package lianxi;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.fox.SpingbootApp;
import com.fox.service.UserService;
@SpringBootTest(classes=SpingbootApp.class)
public class ServiceTest extends TestPortal {
@Autowired
private UserService service;
@Test
public void testListAllUser(){
service.listAllUser(1, "sa444");
}
}
需要pom导入:srping-boot-starter-test