在这种情况下如何编写单元和集成测试?
How to write unit and integration tests in this scenario?
我的算法需要来自 mysql、cassandra、hdfs 等数据源的数据,现在算法处理数据并存储在同一个 locations.logic 中,具有输入 dao、业务逻辑和输出 dao。我已经通过模拟输入和输出 dao 编写了单元测试,但总代码覆盖率较低,因为未涵盖 dao 和服务如何确保此类 类 包含在测试用例中?
如何为 dao 类 编写单元测试?
通过调用真实数据库进行集成测试 ?
How to write unit tests for dao classes?
你通常不会。
Through integration tests by calling real database?
这是正确的做法。对 DAO 类 进行单元测试几乎没有意义,因为为了编写它们,您必须模拟数据库……这将导致测试到底是什么?你不会测试任何东西(或最多模拟)。
我的算法需要来自 mysql、cassandra、hdfs 等数据源的数据,现在算法处理数据并存储在同一个 locations.logic 中,具有输入 dao、业务逻辑和输出 dao。我已经通过模拟输入和输出 dao 编写了单元测试,但总代码覆盖率较低,因为未涵盖 dao 和服务如何确保此类 类 包含在测试用例中? 如何为 dao 类 编写单元测试? 通过调用真实数据库进行集成测试 ?
How to write unit tests for dao classes?
你通常不会。
Through integration tests by calling real database?
这是正确的做法。对 DAO 类 进行单元测试几乎没有意义,因为为了编写它们,您必须模拟数据库……这将导致测试到底是什么?你不会测试任何东西(或最多模拟)。