@@ -6,7 +6,7 @@
*.iml
# Log file
*.log
-
+target
# BlueJ files
*.ctxt
@@ -33,4 +33,8 @@ public class AppController {
PageResult<User> pageResult = new PageResult<>(1, 10, 100L, Collections.singletonList(user));
return Result.success(pageResult);
}
+
+ public String test() {
+ return "123";
+ }
@@ -0,0 +1,20 @@
+package com.alvin.controller;
+import org.junit.Test;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+public class AppControllerTest extends TestBase {
+ @Test
+ public void testFindOne() throws Exception {
+ mockMvc.perform(
+ MockMvcRequestBuilders.get("/user/findOne")
+ .contentType(MediaType.APPLICATION_JSON_UTF8)
+ )
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andReturn();
+ //System.out.println(mvcResult.getResponse().getContentAsString());
+}
@@ -0,0 +1,37 @@
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+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.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+/**
+ * 测试基础类,建议测试service层
+ *
+ * @author tianyunperfect
+ * @date 2020/05/20
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@WebAppConfiguration
+@AutoConfigureMockMvc
+public class TestBase {
+ @Autowired
+ protected MockMvc mockMvc;
+ @Before
+ public void init() {
+ System.out.println("开始测试-----------------");
+ @After
+ public void after() {
+ System.out.println("测试结束-----------------");
@@ -10,8 +10,8 @@ import com.google.gson.Gson;
* https://www.yuque.com/tianyunperfect/ygzsw4/bv1mlg
* <p>
* JsonUtil.toObject(str,JsonHello.class)
- * JSON.parseObject(str2, new TypeReference<List<MyDay>>(){})
- * JSON.parseObject(str2, new TypeReference<JsonHello<Hello>>(){})
+ * JsonUtil.toObject(str2, new TypeReference<List<MyDay>>(){})
+ * JsonUtil.toObject(str2, new TypeReference<JsonHello<Hello>>(){})
*
* @author tianyunperfect
* @date 2020/05/20