简体   繁体   English

如果订单已知,是否可以找到 GoogleTest 运行特定订单的种子?

[英]Is it possible to find the seed for GoogleTest to run a specific order if the order is known?

I have been given a list of 25 tests and a order to run them in that is supposedly causing a failure in the last test.我收到了一份包含 25 个测试的列表以及运行它们的命令,据说这会导致最后一次测试失败。 Unfortunately the tool that was used to find this failure does not save the seed that was used by GoogleTests shuffle to trigger this order.不幸的是,用于查找此故障的工具并未保存 GoogleTests shuffle 用于触发此订单的种子。

So I can of course just run the tests with shuffle and repeat a huge number of times until this order is triggered, but there is quite a lot of permutations to work through.因此,我当然可以使用 shuffle 运行测试并重复大量次,直到触发此命令,但是有很多排列需要解决。 As far as I can tell there isn't a way to just say "Hey run these tests in this order" with GoogleTest aside from knowing the seed to trigger the order.据我所知,除了知道触发订单的种子之外,没有办法只用 GoogleTest 说“嘿,按这个顺序运行这些测试”。

I'm hoping there might be a way to find that seed without actually running the tests - ideally something that could be given the desired order and output the seed, but really just something that given the gtest_filter value just dumps out massive amounts of potential test orders and the seeds that trigger them would be fine.我希望有一种方法可以在不实际运行测试的情况下找到该种子 - 理想情况下,可以给出所需的顺序和 output 种子,但实际上只是给出 gtest_filter 值的东西只是转储了大量潜在的测试订单和触发它们的种子会很好。

Is there any options out there, or I'm I just running with shuffle until I get it?有没有什么选择,或者我只是在随机播放直到我得到它?

There is no such option to specify the order of the tests.没有这样的选项来指定测试的顺序。

However, By default (ie if --gtest_shuffle is not enabled), they run in the declaration order.但是,默认情况下(即如果--gtest_shuffle未启用),它们按声明顺序运行。

I can think of three ways of achieving what you want:我可以想到三种方法来实现你想要的:

  1. Use your favorite scripting language (eg bash, python, nodejs, etc) and regular expressions to modify the original order of the tests to your desired order and create a new test file which then you run without --gtest_shuffle .使用您最喜欢的脚本语言(例如 bash、python、nodejs 等)和正则表达式将测试的原始顺序修改为您想要的顺序并创建一个新的测试文件,然后您可以在没有--gtest_shuffle的情况下运行。

  2. Hack into Google test's source code.侵入谷歌测试的源代码。 You can modify the shuffle function to shuffle the code in the order that you want.您可以修改shuffle function以按照您想要的顺序随机播放代码。

  3. Look into Registering tests programmatically .查看以编程方式注册测试 I think you might be able to register your tests one by one in the order that you want, and I think Googletest will observe that order.我认为您也许可以按照您想要的顺序一一注册您的测试,并且我认为 Googletest 会遵守该顺序。 But this also requires processing your original test file.但这也需要处理您的原始测试文件。

Obviously, none of these methods are ideal, but they might work for a one-off experiment to find the order that you want.显然,这些方法都不是理想的,但它们可能适用于一次性实验以找到您想要的顺序。

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

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