ITeye博客

单元测试

alwaysperfect · 2018-04-24 13:30 · 单元测试 · 行业应用 · Markdown

1、SpringBoot Control单元测试
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {Application.class})
@AutoConfigureMockMvc
public class RyZdryPzZrqControllerTest {
    @Autowired
private MockMvc mockMvc;

    @Test
public void testUpdateDeptName() throws Exception {
        ResultActions result = mockMvc.perform(MockMvcRequestBuilders.post("/xtpz/zrqpz/updateDeptName").contentType(MediaType.APPLICATION_FORM_URLENCODED).param("code", "320584610013").param("name", "测试A"));
        MvcResult mvcResult= result.andReturn();
        ModelAndView modelAndView = mvcResult.getModelAndView();
        System.out.println(modelAndView.toString());
}
}


2、Spring Junit测试
@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration("/config/Spring-db1.xml") 
 @Transactional 
 public class AccountServiceTest1 { 
     @Autowired 
     private AccountService service; 
    
     @Test 
     public void testGetAcccountById() { 
 Account acct = Account.getAccount(1, "user01", 18, "M"); 
         service.insertIfNotExist(acct); 
         Account acct2 = service.getAccountById(1); 
         assertEquals(acct,acct2); 
     } 


 3、Spring手动加载环境
  ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        
        TopProducer topProducer = (TopProducer)context.getBean("topProducer");
        
        topProducer.send("lilixin", "this ia a kafka test msg");

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。