diff --git a/user-service/pom.xml b/user-service/pom.xml index 2c0195c..55fd9b3 100644 --- a/user-service/pom.xml +++ b/user-service/pom.xml @@ -66,16 +66,22 @@ mybatis-typehandlers-jsr310 1.0.1 - - org.springframework.boot - spring-boot-starter-web - + + + + + + + + + + + org.springframework.boot + spring-boot-starter-test + 2.3.1.RELEASE + test + - - org.springframework.boot - spring-boot-starter-test - test - diff --git a/user-service/src/test/java/test/ControllerTest.java b/user-service/src/test/java/test/ControllerTest.java index d174124..0832c7c 100644 --- a/user-service/src/test/java/test/ControllerTest.java +++ b/user-service/src/test/java/test/ControllerTest.java @@ -2,48 +2,27 @@ package test; import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; import com.hp.user.client.entity.AreaVO; -import com.hp.user.client.service.AreaService; import com.hp.user.service.controller.AreaController; -import org.junit.Before; -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ConfigurableApplicationContext; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.List; - -@MapperScan("com.hp.user.service.dao") //扫描的mapper -@SpringBootApplication @NacosPropertySource(dataId = "userdatasource", autoRefreshed = true) - -//@RunWith(SpringRunner.class) -//@SpringBootTest +@RunWith(SpringRunner.class) +@SpringBootTest public class ControllerTest { @Resource - private AreaService areaService; - - @Before - public void init() { - try { - String[] args = new String[]{}; - SpringApplication.run(ControllerTest.class, args); - - }catch(Exception e) { - e.printStackTrace(); - } - - } + private AreaController areaController; @Test public void testQueryAllArea() { - List areas = areaService.getAllArea(); -// List users = areaController.queryAllArea(); - areas.forEach(System.out::println); + List users = areaController.queryAllArea(); + users.forEach(System.out::println); } }