1.通用mapper集成 2.单元测试
This commit is contained in:
@ -8,12 +8,12 @@ import tk.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
|
||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||
@MapperScan(basePackages = "com.ruoyi.bookmark.mapper")
|
||||
@MapperScan(basePackages = { "com.ruoyi.**.mapper" })
|
||||
public class RuoYiApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
@ -40,7 +40,7 @@ public class SqBookmarkController extends BaseController
|
||||
* 测试通用mapper
|
||||
*/
|
||||
@GetMapping("/selectByID")
|
||||
public TableDataInfo selectByID(Long userID) {
|
||||
public TableDataInfo selectByID( Long userID) {
|
||||
List<SqBookmark> list = sqBookmarkService.selectByID(userID);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@ -51,6 +51,7 @@ public class SqBookmarkController extends BaseController
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectBymenuIdUserID")
|
||||
@PreAuthorize("@ss.hasPermi('bookmark:bookmark:list')")
|
||||
public TableDataInfo selectBymenuIdUserID(Long menuID, Long userID) {
|
||||
startPage();
|
||||
List<SqBookmark> list = sqBookmarkService.selectBymenuIdUserID(menuID,userID);
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
* @Date: 2020/08/08 19:10
|
||||
* 功能描述:
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@WebAppConfiguration
|
||||
public class BaseSpringBootTest {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(BaseSpringBootTest.class);
|
||||
@Before
|
||||
public void init() {
|
||||
logger.info("开始测试...");
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
logger.info("测试结束...");
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.ruoyi.web.test.controller;
|
||||
|
||||
|
||||
import com.ruoyi.web.controller.yunbookmark.SqBookmarkController;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
* @Date: 2020/08/08 18:51
|
||||
* 功能描述: SqBookmark 测试类
|
||||
*/
|
||||
public class SqBookmarkTest extends BaseSpringBootTest{
|
||||
|
||||
|
||||
@Autowired
|
||||
private SqBookmarkController sqBookmarkController;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(sqBookmarkController).build();
|
||||
logger.info("setup().........");
|
||||
}
|
||||
@Test
|
||||
public void demo() throws Exception {
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/bookmark/bookmark/2"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andReturn();
|
||||
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user