单元测试
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");
相关推荐
Cocolada 2020-11-12
86427019 2020-06-28
84284855 2020-06-11
snowphy 2020-05-30
lustdevil 2020-08-03
zhengzf0 2020-06-21
宿命java 2020-06-15
snowphy 2020-06-06
Julywhj 2020-05-26
AnndyR 2020-05-15
snowphy 2020-05-12
蛰脚踝的天蝎 2020-11-10
TuxedoLinux 2020-09-11
snowphy 2020-08-19
83540690 2020-08-16
83417807 2020-07-19
张文倩数据库学生 2020-07-19