实现数据库查询用户,获取密码,编写了单元测试类

This commit is contained in:
F嘉阳
2018-01-30 15:47:30 +08:00
commit 91aba6a592
21 changed files with 818 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.fjy.spring;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@@ -0,0 +1,28 @@
package com.fjy.spring.controller;
import org.junit.Test;
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.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class LoginControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void toLoginPage() throws Exception{
mvc.perform(MockMvcRequestBuilders.get("/index"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("/login"));
}
}

View File

@@ -0,0 +1,41 @@
package com.fjy.spring.controller;
import org.junit.Test;
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.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class TestControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void testHello()throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/test"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("Hello Spring"));
}
@Test
public void testDataBase()throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/test/name/root"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("root"));
}
@Test
public void testDataBaseId()throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/test/id/1"))
.andExpect(MockMvcResultMatchers.status().isOk());
}
}