mybatis-plus多數(shù)據(jù)源單元測試報錯
Fail to replace DataSource with an embedded database for tests. If you want an enbedded database please put a supported on on the class path or tune the replace attribute of @AutoConfigreTestDataBase
錯誤原因分析
多數(shù)據(jù)源,但是不能取到數(shù)據(jù)信息
解決方案
在注解中添加@ImportAutoConfiguration(value = {RmasDataSourceConfig.class}, exclude = DataSourceAutoConfiguration.class)
@MybatisPlusTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ImportAutoConfiguration(value = {RmasDataSourceConfig.class}, exclude = DataSourceAutoConfiguration.class)
public class RmasTest {
@Autowired
private RmasMapper rmasMapper;
@Test
void updatePaymentTest(){
rmasMapper.selectById("1");
}
}
注意事項(xiàng)
1.@Test添加以后,沒有啟動鍵,后來發(fā)現(xiàn)引入的包不對,必須引入org.junit.jupiter.api.Test
2.在單元測試如果想引入service
,則需要在注解中添加即可@ImportAutoConfiguration(value = {RmasDataSourceConfig.class, RmasInfoServiceImpl.class}
3.@MyBatisPlusTest
默認(rèn)是事物回滾,需要在測試類上添加@Rollback
注解即可文章來源:http://www.zghlxwxcb.cn/news/detail-515993.html
4.普通版的單元測試需添加注解文章來源地址http://www.zghlxwxcb.cn/news/detail-515993.html
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
到了這里,關(guān)于Mybatis-plus多數(shù)據(jù)源單元測試@MybatisPlusTest的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!