
SpringBoot 里的单元测试,先贴个代码:
@Test @Transactional @Rollback(true) public void addChildResourceTest() { JSONObject requestBody = new JSONObject(); requestBody.accumulate("userId", "admin"); requestBody.accumulate("parentId", "901BCDCA-B272-4F52-B1F0-E47603771611"); JSONArray childResourceList = new JSONArray(); JSONObject child = new JSONObject(); child.accumulate("id", "505BCDCA-B272-5F52-B1F0-E57603771611"); child.accumulate("name", "测试子资源"); child.accumulate("index", 0); child.accumulate("oriResourceId", "6728353b-f448-11e7-8bf7-00155dbc9610"); JSONObject metadata = new JSONObject(); metadata.accumulate("时间", "2018-01-05 11:50:33"); child.accumulate("metadata", metadata); child.accumulate("description", "描述"); childResourceList.add(child); requestBody.accumulate("childReourceList", childResourceList); try { MvcResult updateResult = mockMvc.perform(MockMvcRequestBuilders.post("/api/resource/child").content(requestBody.toString())).andReturn(); int updateStatus = updateResult.getResponse().getStatus(); Assert.assertEquals("success", 200, updateStatus); } catch (Exception e) { e.printStackTrace(); } } 各位大佬,这种 controller 层的单元测试支持回滚吗?测试过程中感觉一会回滚一会又不回滚。。。 1 enaxm 2018-06-01 16:12:24 +08:00 数据库操作只有一个 add? 另外 Transcational 针对的异常是 unchecked |