Passing command line paramters to test fixture

1,578 views
Skip to first unread message

prexpressions

unread,
Dec 4, 2009, 9:35:56 AM12/4/09
to Google C++ Testing Framework
When running the tests on machine A I wish the tests to run
differently to when running the tests on machine B.

My idea is that I would pass a specific command line parameter to the
exe at run time and within the fixture I would check this parameter
and then switch the test accordingly.


(For those interested machine A has different hardware to machine B,
the tests remain logical to perform but the expected results are
different. Is there support in the framework to somehow tell the
fixture to do something different according to a command line switch?)

Josh Kelley

unread,
Dec 4, 2009, 1:12:04 PM12/4/09
to prexpressions, Google C++ Testing Framework
On Fri, Dec 4, 2009 at 9:35 AM, prexpressions <prexpr...@googlemail.com> wrote:
My idea is that I would pass a specific command line parameter to the
exe at run time and within the fixture I would check this parameter
and then switch the test accordingly.

(For those interested machine A has different hardware to machine B,
the tests remain logical to perform but the expected results are
different.  Is there support in the framework to somehow tell the
fixture to do something different according to a command line switch?)

Google Test doesn't directly support this, but it leaves untouched any command line arguments that it doesn't recognize after you call InitGoogleTest, as described here:

http://code.google.com/p/googletest/wiki/GoogleTestPrimer#Writing_the_main%28%29_Function

So you're free to parse whatever additional command line arguments you want at that point.

(However, depending on what exactly you're testing, it might instead be better to mock out the hardware-dependent parts of your code so that your unit tests become hardware-independent.)

--
Josh Kelley
Reply all
Reply to author
Forward
0 new messages