unit test

1. SpringBoot Control unit testing
@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 test
@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 manually loads the environment
  ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        
        TopProducer topProducer = (TopProducer)context.getBean("topProducer");
        
        topProducer.send("lilixin", "this ia a kafka test msg");

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325340593&siteId=291194637