arts-week7

Algorithm

  1. 513. Find Bottom Left Tree Value - LeetCode
  2. 559. Maximum Depth of N-ary Tree - LeetCode
  3. 766. Toeplitz Matrix - LeetCode
  4. 893. Groups of Special-Equivalent Strings - LeetCode
  5. 696. Count Binary Substrings - LeetCode
  6. 165. Compare Version Numbers - LeetCode

Review

Goodbye Python. Hello Go.

介绍 Go 语言对比 Python 的优点。

Tip

编写针对RestfullAPI的测试用例,以前测试都是写一个Controller,构造一个形似/test/user的映射进行测试

package com.imooc.demo.web.controller;

import org.junit.Before;
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.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;


/**
 * Author:   yangdc
 * Date:     2018/8/26 4:13
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserControllerTest {
    @Autowired
    private WebApplicationContext context;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
    }

    @Test
    public void whenQuerySuccess() throws Exception {
        mockMvc.perform(get("/user/query1")
                .contentType(MediaType.APPLICATION_JSON_UTF8))
                .andExpect(status().isOk()) // 返回状态码为200
                .andExpect(jsonPath("$.length()").value(3));  // 返回数据的集合长度是3
    }

    @Test
    public void whenQuerySuccess2() throws Exception {
        mockMvc.perform(get("/user/query2")
                .param("username", "alex")
                .contentType(MediaType.APPLICATION_JSON_UTF8))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.length()").value(3));
    }

    @Test
    public void whenQuerySuccess3() throws Exception {
        mockMvc.perform(get("/user/query3")
                .param("username", "alex")
                .param("age", "18")
                .param("ageTo", "22")
                .param("size", "15")
                .param("page", "3")
                .param("sort", "age,desc")
                .contentType(MediaType.APPLICATION_JSON_UTF8))
                .andExpect(status().isOk()) // 返回状态码为200
                .andExpect(jsonPath("$.length()").value(3));  // 返回数据的集合长度是3
    }
}

Share

  1. 《算法图解》之散列表
  2. Spring Security开发安全的REST服务0102

猜你喜欢

转载自www.cnblogs.com/okokabcd/p/9575893.html