如何为Spring类编写Junit
如何在没有任何数据库依赖的情况下对Spring类执行Junit测试 例如,如果我想为一个服务类(自动相关Dao)编写junit测试用例,那么数据源将被实例化为@autowired类如何为Spring类编写Junit,spring,spring-mvc,junit,Spring,Spring Mvc,Junit,如何在没有任何数据库依赖的情况下对Spring类执行Junit测试 例如,如果我想为一个服务类(自动相关Dao)编写junit测试用例,那么数据源将被实例化为@autowired类 在测试过程中,是否有任何方法可以使用其他组件作为junit期间的内存/临时数据库?可以选择使用嵌入式数据库作为数据源: <jdbc:embedded-database id="dataSource" type="HSQL"> <jdbc:script location="classp
在测试过程中,是否有任何方法可以使用其他组件作为junit期间的内存/临时数据库?可以选择使用嵌入式数据库作为数据源:
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:schema.sql"/>
</jdbc:embedded-database>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:test-data.sql"/>
</jdbc:initialize-database>
Doc link:Google“mocking frameworks”,我个人使用Java,但还有其他选择。您的用例可能需要模拟DAO,并让它们返回您想要的任何测试数据。