简体   繁体   English

db单元测试。 约束失效

[英]Db unit tests. Constraints disabling

I have a set of unit tests which test my DAO layer. 我有一组测试我的DAO层的单元测试。 I have following requirements: - For one subset of tests I need to disable constraints(foreign key, unique, not null). 我有以下要求:-对于测试的一个子集,我需要禁用约束(外键,唯一,不为null)。 - For other subset I need to remain their (I check data integrity here). -对于其他子集,我需要保留其子集(我在此处检查数据完整性)。

So for several test I want to enable constraints, for other to disable. 因此,对于几个测试,我想启用约束,而其他则禁用。

Firstly I tried to use DbMantainer(part of Unitils), because it has disable constraint option. 首先,我尝试使用DbMantainer(Unitils的一部分),因为它具有禁用约束选项。 But after that I looked into sources and found that it can only remove(through alter table) constraints at the moment when I start migration process. 但是之后,我查看了源代码,发现它仅在我开​​始迁移过程时才能删除(通过alter table)约束。 After constraints were removed once(before I launch first test), I can't enable their later (integrity tests). 删除约束一次后(在我启动第一个测试之前),以后就不能启用它们(完整性测试)。

So my questions are: 1. Can you suggest me other tools (like DbMantainer or Unitils) which can disable constraints? 所以我的问题是:1.您能否建议我其他可以禁用约束的工具(例如DbMantainer或Unitils)? 2. If no such tools exist what is in your opinion the best option to disable and enable constraints in db unit testing? 2.如果不存在这样的工具,您认为在数据库单元测试中禁用和启用约束的最佳选择是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM