First, I am new to googletest framework so be kind.
I have a function
void setID(const int id)
{
ID = id;
}
where ID is a global unsigned int
. (Yes, globals are bad, I am just trying to figure what I am doing.)
My unit test looks like this
TEST_F(TempTests, SetId)
{
// Arrange
int id = -99;
// Act
setId(id);
// Assert
EXPECT_EQ(id, ID);
}
The problem is my unit test always passes and I need it to fail as ID should have been a signed int not an unsigned int. If I hadn't visually caught the error the unit test would have passed and it could have caused errors later on.
To make sure that this doesn't happen in the future it would be best if the unit test comparison failed in this case.
I have tried static casting id
and ID
to signed and unsigned ints in various ways.
I have tried doing EXPECT_TRUE(id == ID)
with static casting the variables to signed and unsigned ints in various ways.
But in all of these cases the result is a passing test.
So how can I get gtest to compare the signed value of id
and unsigned value of ID
so that the test will fail because id
will be -99 and ID
will be 4294967197?