Skip to content

Instantly share code, notes, and snippets.

@Affonso-Gui
Created April 30, 2023 01:55
Show Gist options
  • Save Affonso-Gui/08ef09a072f8ef0b27ea7f3ce4cb2ea7 to your computer and use it in GitHub Desktop.
Save Affonso-Gui/08ef09a072f8ef0b27ea7f3ce4cb2ea7 to your computer and use it in GitHub Desktop.
Minimal TYPED_TEST example using gtest and gmock
// In Visual Studio:
// While the builtin Google Test Adapter doesn't support gmock, use the following
// https://www.nuget.org/packages/gmock/1.11.0
#include <list>
#include <gtest/gtest.h>
// Google Test Manual:
// https://github.com/google/googletest/blob/main/docs/advanced.md#typed-tests
template <typename T>
class FooTest : public testing::Test {
public:
using List = std::list<T>;
};
using MyTypes = ::testing::Types<int, float, double>;
TYPED_TEST_SUITE(FooTest, MyTypes);
TYPED_TEST(FooTest, DoesBlah) {
typename TestFixture::List list;
list.push_back(0);
list.push_back(1);
list.push_back(2);
ASSERT_EQ(list, std::list<TypeParam>({ 0, 1, 2 }));
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment