GoogleTest with underscore in test case name

Sysprogs forums Forums VisualGDB GoogleTest with underscore in test case name

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21749
    Jensa
    Participant

    Hi,

    We got some strange behavior when we started making google unit tests that some tests just vanished from the Test Explorer but ran fine when just running it from command line etc.

    It seems VisualGDB doesn’t handle underscore in the test case name properly and they simply vanish from the Test Explorer when you try to run them. From google’s FAQ it should be ok with underscore in the test case name but not anywhere else. (It usually works in other places but you should avoid it as future changes to gtest could make them invalid.)

    As in, change the example template from:
    TEST(DemoTestGroup, FailingTest)

    to

    TEST(DemoTestGroup, Failing_Test)

    breaks everything.

    #21759
    Jensa
    Participant

    Hmm, it seems what I read earlier is no longer true and they now discourage the use of underscore in any name so I guess we’ll just stop using it instead.

    #21764
    support
    Keymaster

    Hi,

    Yes, GoogleTest uses the <GroupName>_<TestName> syntax for internal test symbol names, so VisualGDB indeed gets confused when the test name itself contains an underscore.

    You could work around this by patching the %LOCALAPPDATA%\VisualGDB\TestFrameworks\com.sysprogs.unittest.googletest\TestFramework.xml file as shown below:

    <TestIDRegex>([^_]*)_(.*)</TestIDRegex>

    However, this will break if the test group names contain underscores. So if it’s possible to avoid underscores in your group/test names, we would advise doing that instead.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.