【发布时间】:2014-02-11 08:00:37
【问题描述】:
我是 jUnit 的新手,我的任务是为具有一些复杂数据库组件的应用程序编写 jUnit 测试用例。我可以为 DB 组件编写测试用例,这些测试用例在我的本地 maven 构建创建中运行良好。但是在部署框中,从 jenkins maven 命令创建构建时,我没有可用的数据库。请推荐!!
【问题讨论】:
标签: java maven testing junit jenkins
我是 jUnit 的新手,我的任务是为具有一些复杂数据库组件的应用程序编写 jUnit 测试用例。我可以为 DB 组件编写测试用例,这些测试用例在我的本地 maven 构建创建中运行良好。但是在部署框中,从 jenkins maven 命令创建构建时,我没有可用的数据库。请推荐!!
【问题讨论】:
标签: java maven testing junit jenkins
jUnit 有dbUnit 扩展,旨在在测试运行之间创建一个已知的可重现状态。在 CI 盒(以及本地)上与内存数据库(例如 HSQL 或 H2)一起使用应该很适合您。
干杯,
【讨论】:
通常的方法是在内存数据库环境中为 CRUD 功能编写单元测试。不完全是真实的东西,但危险性较小。来看看
http://www.h2database.com/html/main.html
http://www.oracle.com/technetwork/articles/javase/javadb-10-5-142692.html
【讨论】:
您可以根据在真实数据库上运行的模拟和集成测试将您的测试与单元测试分开。仅在 Jenkins 中运行单元测试
【讨论】:
I am working same kind of project. In our application we use test schema and a reusable class which loads the data from the XML(File is same as test class) and Cache the data and removes the data from the table, so that Unit test get intended data.
We set different profile and these are set via JVM arguments. And these profile have the database details and any other admin stuff required. In case of Junit to run we use the unit test profile.
【讨论】: