Browse Source

feat:[单元测试]集成pom,简单测试

master
HanLong 3 weeks ago
parent
commit
676a835f87
3 changed files with 62 additions and 0 deletions
  1. +6
    -0
      hxhq-modules/hxhq-system/pom.xml
  2. +29
    -0
      hxhq-modules/hxhq-system/src/test/java/com/hxhq/business/controller/TestControllerTest.java
  3. +27
    -0
      hxhq-modules/hxhq-system/src/test/java/com/hxhq/business/service/ITestServiceTest.java

+ 6
- 0
hxhq-modules/hxhq-system/pom.xml View File

@ -71,6 +71,12 @@
<artifactId>hxhq-common-swagger</artifactId> <artifactId>hxhq-common-swagger</artifactId>
</dependency> </dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

+ 29
- 0
hxhq-modules/hxhq-system/src/test/java/com/hxhq/business/controller/TestControllerTest.java View File

@ -0,0 +1,29 @@
package com.hxhq.business.controller;
import com.hxhq.system.HxhqSystemApplication;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.junit.jupiter.api.Assertions.*;
@AutoConfigureMockMvc
@SpringBootTest(classes = HxhqSystemApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void testGet() throws Exception {
ResultActions perform = mvc.perform(MockMvcRequestBuilders.get("/business/test/info?id=1"));
MockHttpServletResponse response = perform.andReturn().getResponse();
System.out.println(response.getContentAsString());
}
}

+ 27
- 0
hxhq-modules/hxhq-system/src/test/java/com/hxhq/business/service/ITestServiceTest.java View File

@ -0,0 +1,27 @@
package com.hxhq.business.service;
import com.hxhq.system.HxhqSystemApplication;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.Assert;
import java.util.List;
@SpringBootTest(classes = HxhqSystemApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ITestServiceTest {
@Autowired
private ITestService testService;
@Test
public void test() {
List<com.hxhq.business.domain.Test> list = testService.list();
Assertions.assertEquals(20, list.size(), "数量错误");
}
}

Loading…
Cancel
Save