编写 service项目
其中@Transactional进行数据回滚
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@Transactional
@ActiveProfiles("unittest")
@Sql(statements = {
"insert into `aa`(`id`,`a`,`b`,`c`,`d`,`create_user`,`update_user`,`create_time`,`update_time`,`ts`,`is_delete`) values " +
"(1,1,'aa',1,'dd','aa','aa','2020-06-01 02:19:55','2020-06-01 02:19:55','2020-06-01 10:21:07',0);"
})
public class serviceTest { //TODO }
编写controller项目配置
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig(classes = application.class)
@SpringJUnitWebConfig
@ActiveProfiles("unittest")
@TestPropertySources({
@TestPropertySource("classpath:prop/pz1.properties"),
@TestPropertySource("classpath:prop/pz2.properties"),
@TestPropertySource("classpath:prop/pz3.properties"),
@TestPropertySource("classpath:prop/pz4.properties")
})
public class BaseTest {
@Autowired
protected WebApplicationContext context;
protected MockMvc mockMVC;
@Before
public void initMockMvc() {
setcontext();
mockMVC = MockMvcBuilders.webAppContextSetup(context).build();
}
/**
* 模拟登录设置登录上下文
*/
private void setcontext() {
}
}