I have a global variable that is configured with a function. I am writing a gtest to test if the function is working, by checking if the global variable changes after the function is called.
In main.cpp:
bool flag{false};
void FlipFlag() {
flag = true;
}
In main.h:
void FlipFlag();
In main_TEST.cpp:
#include "gtest/gtest.h"
#include "main.h"
TEST(MainTest, TestFlagFlip) {
EXPECT_FALSE(flag);
FlagFlip();
EXPECT_TRUE(flag);
}
How do I access the variable flag for testing? I do not want to declare flag in main.h. Is this the best way to test the flag?