Using Fixture and Value-Parameterized Tests together?

27 views
Skip to first unread message

pschwenn

unread,
Dec 16, 2009, 9:11:45 PM12/16/09
to Google C++ Testing Framework
Googletesters,

I finally figured out how to write Value_Parameterized TESTs. But the
TESTs I want to parameterize are already using a TEST Fixture.

Is there a way to Parameterized TESTs that work with a Fixture? It
doesn't look like its possible, because a TEST can't be a TEST_P...
and a TEST_F... at the same time. Is that correct? Is there a way
around it.

Thank you,

Peter Schwenn

Zhanyong Wan (λx.x x)

unread,
Dec 17, 2009, 12:37:17 AM12/17/09
to pschwenn, Google C++ Testing Framework

Parameterized tests can use fixtures. In fact, you _have to_ use a
fixture, as explained here:

http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide#Value_Parameterized_Tests

"To write value-parameterized tests, first you should define a fixture
class. It must be derived from ::testing::TestWithParam<T>, where T is
the type of your parameter values. ..."

>
> Thank you,
>
> Peter Schwenn
>

--
Zhanyong

pschwenn

unread,
Dec 17, 2009, 11:32:05 AM12/17/09
to Google C++ Testing Framework
Zhanyong,

Thanks for the repsonse.

Am I right in concluding that I would take my current Test Fixture
code, and integrate it with the code that I am using to construct my
new Parameterizing fixture. So that my TESTs, that once had a Test
Fixture and were named TEST_F(...) would now be both Fixtured and
Parameterized (by the same "integrated" fixture code) and would be
named TEST_P(...) ?

On Dec 17, 12:37 am, Zhanyong Wan (λx.x x) <w...@google.com> wrote:


> On Wed, Dec 16, 2009 at 6:11 PM, pschwenn <pschw...@gmail.com> wrote:
> > Googletesters,
>
> > I finally figured out how to write Value_Parameterized TESTs.  But the
> > TESTs I want to parameterize are already using a TEST Fixture.
>
> > Is there a way to Parameterized TESTs that work with a Fixture?  It
> > doesn't look like its possible, because a TEST can't be a TEST_P...
> > and a TEST_F... at the same time.  Is that correct?  Is there a way
> > around it.
>
> Parameterized tests can use fixtures.  In fact, you _have to_ use a
> fixture, as explained here:
>

> http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide#Valu...

Zhanyong Wan (λx.x x)

unread,
Dec 17, 2009, 11:52:15 AM12/17/09
to pschwenn, Google C++ Testing Framework
Yes.

--
Zhanyong

Reply all
Reply to author
Forward
0 new messages