springboot整合Junit 测试类


1、修改pom



    org.springframework.boot
    spring-boot-starter-test
    test
2、编写测试类 (UserServiceTest)
import com.subject.DemoApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class DemocontrollerTest {

    @Autowired
    private Democontroller democontroller;

    @Test
    public void test01() {
        final String s = democontroller.test01();
        System.out.println("s = " + s);
    }
}
     

相关