Repeating tests using different test fixtures

1,874 views
Skip to first unread message

Austin Kinross

unread,
Sep 24, 2014, 7:27:25 PM9/24/14
to googletes...@googlegroups.com
Hi,

Is it possible to author tests and test fixtures such that the tests are run multiple times using different test fixtures, without duplicating the test code?

For example, in the Google Testing Framework 'Queue' sample (https://code.google.com/p/googletest/source/browse/trunk/samples/sample3_unittest.cc), I might create a new test fixture (say 'QueueTest2') whose 'SetUp()' method differs very slightly from 'QueueTest'. I'd then like to run exactly the same tests (i.e. 'DefaultConstructor', 'Dequeue', and 'Map') twice, once using 'QueueTest2' and once using 'QueueTest', without duplicating code.

If this isn't possible, what is the best way to author tests like this to minimize code duplication?

Thanks,
Austin

Samuel Benzaquen

unread,
Sep 25, 2014, 10:00:26 AM9/25/14
to Austin Kinross, Google C++ Testing Framework
On Wed, Sep 24, 2014 at 7:27 PM, Austin Kinross <auki...@microsoft.com> wrote:
Hi,

Is it possible to author tests and test fixtures such that the tests are run multiple times using different test fixtures, without duplicating the test code?

You can't change the fixture itself, but you can change a template parameter passed to the fixture by using Typed tests.

For example, in the Google Testing Framework 'Queue' sample (https://code.google.com/p/googletest/source/browse/trunk/samples/sample3_unittest.cc), I might create a new test fixture (say 'QueueTest2') whose 'SetUp()' method differs very slightly from 'QueueTest'. I'd then like to run exactly the same tests (i.e. 'DefaultConstructor', 'Dequeue', and 'Map') twice, once using 'QueueTest2' and once using 'QueueTest', without duplicating code.

If this isn't possible, what is the best way to author tests like this to minimize code duplication?

Thanks,
Austin

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--


Дмитрий Киселёв

unread,
Oct 8, 2015, 9:20:06 AM10/8/15
to Google C++ Testing Framework
Hello!

What if I need to run some tests using different fixtures, but all fixtures contain object of the same type with only different values?

Thanks,
Dmitriy

четверг, 25 сентября 2014 г., 17:00:26 UTC+3 пользователь Samuel Benzaquen написал:
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframework+unsub...@googlegroups.com.

Samuel Benzaquen

unread,
Oct 8, 2015, 1:34:35 PM10/8/15
to Дмитрий Киселёв, Google C++ Testing Framework
On Thu, Oct 8, 2015 at 6:28 AM, Дмитрий Киселёв <dima13...@gmail.com> wrote:
Hello!

What if I need to run some tests using different fixtures, but all fixtures contain object of the same type with only different values?


четверг, 25 сентября 2014 г., 17:00:26 UTC+3 пользователь Samuel Benzaquen написал:
On Wed, Sep 24, 2014 at 7:27 PM, Austin Kinross <auki...@microsoft.com> wrote:
Hi,

Is it possible to author tests and test fixtures such that the tests are run multiple times using different test fixtures, without duplicating the test code?

You can't change the fixture itself, but you can change a template parameter passed to the fixture by using Typed tests.

For example, in the Google Testing Framework 'Queue' sample (https://code.google.com/p/googletest/source/browse/trunk/samples/sample3_unittest.cc), I might create a new test fixture (say 'QueueTest2') whose 'SetUp()' method differs very slightly from 'QueueTest'. I'd then like to run exactly the same tests (i.e. 'DefaultConstructor', 'Dequeue', and 'Map') twice, once using 'QueueTest2' and once using 'QueueTest', without duplicating code.

If this isn't possible, what is the best way to author tests like this to minimize code duplication?

Thanks,
Austin

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages