Skip to content

Commit dad4e37

Browse files
committed
Reuse fixtures between tests
1 parent 450c120 commit dad4e37

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

tests.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ using namespace tao::graphqlpeg;
1919

2020
class TodayServiceCase : public ::testing::Test
2121
{
22-
protected:
23-
void SetUp() override
22+
public:
23+
static void SetUpTestCase()
2424
{
2525
std::string fakeAppointmentId("fakeAppointmentId");
2626
_fakeAppointmentId.resize(fakeAppointmentId.size());
@@ -35,15 +35,15 @@ class TodayServiceCase : public ::testing::Test
3535
std::copy(fakeFolderId.cbegin(), fakeFolderId.cend(), _fakeFolderId.begin());
3636

3737
auto query = std::make_shared<today::Query>(
38-
[this]() -> std::vector<std::shared_ptr<today::Appointment>>
38+
[]() -> std::vector<std::shared_ptr<today::Appointment>>
3939
{
4040
++_getAppointmentsCount;
4141
return { std::make_shared<today::Appointment>(std::vector<unsigned char>(_fakeAppointmentId), "tomorrow", "Lunch?", false) };
42-
}, [this]() -> std::vector<std::shared_ptr<today::Task>>
42+
}, []() -> std::vector<std::shared_ptr<today::Task>>
4343
{
4444
++_getTasksCount;
4545
return { std::make_shared<today::Task>(std::vector<unsigned char>(_fakeTaskId), "Don't forget", true) };
46-
}, [this]() -> std::vector<std::shared_ptr<today::Folder>>
46+
}, []() -> std::vector<std::shared_ptr<today::Folder>>
4747
{
4848
++_getUnreadCountsCount;
4949
return { std::make_shared<today::Folder>(std::vector<unsigned char>(_fakeFolderId), "\"Fake\" Inbox", 3) };
@@ -61,16 +61,34 @@ class TodayServiceCase : public ::testing::Test
6161
_service = std::make_shared<today::Operations>(query, mutation, subscription);
6262
}
6363

64-
std::vector<unsigned char> _fakeAppointmentId;
65-
std::vector<unsigned char> _fakeTaskId;
66-
std::vector<unsigned char> _fakeFolderId;
64+
static void TearDownTestCase()
65+
{
66+
_fakeAppointmentId.clear();
67+
_fakeTaskId.clear();
68+
_fakeFolderId.clear();
69+
_service.reset();
70+
}
6771

68-
std::shared_ptr<today::Operations> _service;
69-
size_t _getAppointmentsCount = 0;
70-
size_t _getTasksCount = 0;
71-
size_t _getUnreadCountsCount = 0;
72+
protected:
73+
static std::vector<unsigned char> _fakeAppointmentId;
74+
static std::vector<unsigned char> _fakeTaskId;
75+
static std::vector<unsigned char> _fakeFolderId;
76+
77+
static std::shared_ptr<today::Operations> _service;
78+
static size_t _getAppointmentsCount;
79+
static size_t _getTasksCount;
80+
static size_t _getUnreadCountsCount;
7281
};
7382

83+
std::vector<unsigned char> TodayServiceCase::_fakeAppointmentId;
84+
std::vector<unsigned char> TodayServiceCase::_fakeTaskId;
85+
std::vector<unsigned char> TodayServiceCase::_fakeFolderId;
86+
87+
std::shared_ptr<today::Operations> TodayServiceCase::_service;
88+
size_t TodayServiceCase::_getAppointmentsCount = 0;
89+
size_t TodayServiceCase::_getTasksCount = 0;
90+
size_t TodayServiceCase::_getUnreadCountsCount = 0;
91+
7492
TEST_F(TodayServiceCase, QueryEverything)
7593
{
7694
auto ast = peg::parseString(R"gql(

0 commit comments

Comments
 (0)