如何在GoogleTest中运行特定测试用例 [英] How to run specific test cases in GoogleTest

查看:522
本文介绍了如何在GoogleTest中运行特定测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的项目写一个函数/方法,它会询问用户你要运行哪些测试用例?
它看起来像下面...,

I am trying to write a function/method for my project, which will ask to user which all test cases are you going to run? It looks like below...,

Test_Cases_1
         |_TestNo1
         |_TestNo2....so on
Test_Cases_2
         |_TestNo1
         |_TestNo2....so on
....
....so on
Test_Cases_N
         |_TestNo1
         |_TestNo2....so on

现在的挑战是,在运行项目时,它应该提示我,你想要执行的所有测试用例?
如果我选择 Test_Cases_1 Test_Cases_N 。然后它应该执行这两个测试用例,并应该将所有其他从 Test_Cases_2到.... 。在结果窗口中,我也想看到 Test_Cases_1 Test_Cases_N 的结果。

So, now the challenge is while running the project it should prompt me what all test cases you would like to execute? If I select Test_Cases_1 and Test_Cases_N. Then it should execute these two test cases and should exclude all other from Test_Cases_2 to ..... In result window also I would like to see the results of Test_Cases_1 and Test_Cases_N.

所以,如果我看到GoogleTest,有一个方法 test_case_to_run_count();
但是所有的测试用例都是通过Test_F()方法注册的。
所以,我做了很多分析,但仍然没有找到任何解决方案。
请帮助我。

So, if I will see the GoogleTest, there is a method called test_case_to_run_count(); But all the test cases are getting registered with Test_F() method. So, I did lots of analysis, but still did not find any solution. Please help me.

推荐答案

您可以使用高级选项来运行Google测试。

You could use advanced options to run Google tests.

要仅运行一些单元测试,您可以使用 - gtest_filter = Test_Cases1 * 命令行选项,值为正则表达式。我认为这将解决你的问题。

To run only some unit tests you could use --gtest_filter=Test_Cases1* command line option with value which is regular expression. I think it will solve your problem.

UPD:

运行特定测试用例。将gtest与您的GUI集成是另一回事,我不能真正评论,因为您没有提供您的方法的详细信息。但我相信以下方法可能是一个好的开始:

Well, the question was how to run specific test cases. Integration of gtest with your GUI is another thing, which I can't really comment, because you didn't provide details of your approach. However I believe the following approach might be a good start:


  1. 通过运行测试获取所有测试用例 - gtest_list_tests

  2. 将此数据解析到您的GUI中

  3. 选择要运行的测试用例

  4. 使用选项 - gtest_filter 运行测试可执行文件

  1. Get all testcases by running tests with --gtest_list_tests
  2. Parse this data into your GUI
  3. Select test cases you want ro run
  4. Run test executable with option --gtest_filter

这篇关于如何在GoogleTest中运行特定测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆