简体   繁体   English

让QUnit按顺序运行测试

[英]Getting QUnit to run tests in order

I've used qunit to write a series of tests for javascript code I have. 我用qunit编写了一系列javascript代码测试。 Right now for some reason, the first test in my list will run, and then the LAST test in the list runs, followed by the 2nd to last, 3rd to last, 4th to last, etc... It's crucial for my tests that things run in the order that I have them in. I tried turning off that option where qunit runs tests that failed last time first, but it's still doing this. 现在由于某种原因,我的列表中的第一个测试将运行,然后列表中的最后一个测试运行,然后是第二个到最后一个,第三个到最后一个,第四个到最后一个等等...这对我的测试至关重要事情按照我让他们进入的顺序运行。我尝试关闭该选项,其中qunit运行上次失败的测试,但它仍然这样做。 Is there any way to fix this? 有没有什么办法解决这一问题?

First, figure out why your tests MUST run in a specific order. 首先,弄清楚为什么你的测试必须按特定顺序运行。 The whole point of unit testing is that the tests are atomic and it should be possible to run them in any order - if your test suite isn't capable of this, you need to figure out why as it may represent a larger problem. 单元测试的重点是测试是原子的,应该可以按任何顺序运行它们 - 如果你的测试套件不具备这个功能,你需要找出原因,因为它可能代表一个更大的问题。

If you can't figure it out, then you may need to break your test suite up into smaller groups of tests until you find the one(s) causing the issue. 如果您无法弄明白,那么您可能需要将测试套件分成更小的测试组,直到找到导致问题的测试套件为止。

edit : Found this reference at http://www.educatedguesswork.org/2011/06/curse_you_qunit_1.html . 编辑 :在http://www.educatedguesswork.org/2011/06/curse_you_qunit_1.html上找到此参考。 Apparently, adding this to your test suite will help QUnit.config.reorder = false; 显然,将其添加到测试套件将有助于QUnit.config.reorder = false;

Maybe you could consider placing the code that does each major computation in a function that has a test at the beginning that checks if the computation was already done. 也许你可以考虑将每个主要计算的代码放在一个函数中,该函数在开始时检查计算是否已经完成。 If the computation is not done, do the computation and save the result somewhere. 如果未完成计算,请执行计算并将结果保存在某处。 If the computation has already been done then just return the results. 如果计算已经完成,那么只返回结果。 In this way you can have a single computation for all the tests but still be autonomous to the order the tests are done. 通过这种方式,您可以对所有测试进行单次计算,但仍然可以对测试完成的顺序进行自主计算。

I can relate to the problems of time consuming computations in unit testing, but it is imperative to the test group to be able to take any unit test and execute as an independent autonomous test. 我可以在单元测试中涉及耗时计算的问题,但是测试组必须能够进行任何单元测试并作为独立的自主测试执行。 This is especially true when a critical problem comes up and has to be addressed specifically. 当出现严重问题并且必须特别解决时,尤其如此。

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

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