简体   繁体   English

dbUnit如何防止同时运行多个测试?

[英]DbUnit how to guard against multiple tests running at the same time?

I am working on a test environment for a project, and am looking into using DbUnit.NET to do a lot of the database interaction testing. 我正在一个项目的测试环境中工作,并且正在考虑使用DbUnit.NET进行很多数据库交互测试。 I do have one very big question though: 我确实有一个很大的问题:

We are running against Oracle, and setting up a seperate test DB instance for every developer really isn't feasible (especially since we only have 1 DBA who is already strapped for time). 我们正在与Oracle对抗,并且为每个开发人员设置一个单独的测试数据库实例确实是不可行的(特别是因为我们只有1个已经被时间束缚的DBA)。 This means that all developers and out Continuous Integration server all need to use the same DB schema. 这意味着所有开发人员和Continuous Integration服务器都需要使用相同的数据库架构。

So, on to the question: is there a good way to prevent more than 1 person from testing at the same time? 因此,提出一个问题:是否有一个好的方法可以防止一个以上的人同时进行测试? It would be easy to put a record in a db table that indicates that a test is running, then remove it after tests are finished, but NUnit doesn't have any way to run something at test session start and end. 在db表中放置一条表明正在运行测试的记录,然后在测试完成后将其删除很容易,但是NUnit无法在测试会话的开始和结束时运行任何记录。

Any other thoughts? 还有其他想法吗? It seems like it should be a pretty common issue... or does everyone actually run separate DB instances for every developer/tester that might run the tests? 看来这应该是一个非常普遍的问题……还是每个人都为每个可能运行测试的开发人员/测试人员实际运行单独的数据库实例吗?

您可以使用[TestFixtureSetUp]属性来注入您的标志,该标志指示测试正在运行,作为模拟“真实”信号量的一种方式。

We used a dummy table with a single record as a lock token when we ran database tests for a bunch of developers on a shared database. 当我们在共享数据库上为一群开发人员运行数据库测试时,我们使用了具有单个记录的虚拟表作为锁定令牌。 We actually acquired the lock for each test case individually so that a developer who wants to run one test case doesn't have to wait for another developer who's running the whole suite to finish. 实际上,我们实际上为每个测试用例都获取了锁,这样,想要运行一个测试用例的开发人员就不必等待运行整个套件的另一个开发人员完成。 We made each test set up its own data - no carry over between test methods. 我们使每个测试设置了自己的数据-测试方法之间没有保留。

We used the database locking mechanism to actually queue tests instead of failing when someone else is already running a test. 我们使用数据库锁定机制将测试实际排队,而不是在其他人已经在运行测试时使测试失败。 I think Oracle's locking algorithm is a little different, so I don't know how that would work. 我认为Oracle的锁定算法有些不同,因此我不知道该如何工作。

The only place we ran into trouble was when a developer wanted to step through a test in debug mode. 我们唯一遇到麻烦的地方是开发人员想要在调试模式下逐步进行测试。 That would block any other developers who wanted to run a test until he released the debugger. 这将阻止任何其他想要运行测试的开发人员,直到他发布调试器。 We wrote the current user's name into a dummy table, and had the locking mechanism print a message if it got blocked for more than 30 seconds: "Bob is currently running a test and has been for the last 5 minutes." 我们将当前用户的名字写到一个虚拟表中,并让锁定机制在被阻止超过30秒时打印一条消息:“ Bob当前正在运行测试,并且已经运行了5分钟。”

This was OK, but it was a lot of work to maintain. 可以,但是要维护很多工作。 We tried to keep the number of database tests small, and do most of our tests as pure unit tests in memory. 我们试图使数据库测试的数量保持较小,并且将大多数测试作为内存中的纯单元测试进行。

Something I did in a problem with some similarities to this one: 我在一个与此类似的问题中所做的事情:

The program had a configuration variable that was added to the front of all relevant items. 该程序具有一个配置变量,该变量已添加到所有相关项目的前面。 Each station had it's own setting, properly set there would be no conflicts. 每个电台都有自己的设置,正确设置不会有冲突。

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

相关问题 针对多个版本的jQuery运行jasmine测试 - Running jasmine tests against multiple versions of jQuery 针对多个实现运行相同的测试 - running the same test against multiple implementations 同时运行多个测试时,数据访问层引发事务异常 - Data access layer throws transaction exceptions when running multiple tests at the same time 同时运行所有单元测试时出现异常 - Exception whilst running all unit tests at the same time 在play 2.0 scala中的同一个FakeApplication()中运行多个测试 - running multiple tests within the same FakeApplication() in play 2.0 scala 在多个接口实现上运行同一组参数化测试 - Running same set of parameterized tests on multiple Interface implementations 像往常一样针对 docker 容器或 dockerize 测试运行测试? - Running tests as usual against docker containers or dockerize tests? 当多个单元测试复制同一文件时,运行所有单元测试失败 - When multiple unit tests copy the same file, running all unit tests fail 使用 Jest 获取测试运行时间 - Get tests running time with Jest 在执行单元测试时如何防止dbunit生成database.script文件 - how to prevent dbunit from generating database.script file when executing unit tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM