dimanche 27 mars 2016

Google Test - Value parameterized test

I am studying parameterized tests within the Google Test framework. Examples I have found test boolean functions, like:

bool Number::isPrime(int n);

The test can be written like this:

class NumberTest : public testing::TestWithParam<int>
{
    public:
    Number nr;
};

TEST_P(NumberTest, isPrime_nonPrime_returnsFalse)
{
  ASSERT_FALSE(nr.isPrime(GetParam()));
}

INSTANTIATE_TEST_CASE_P(InstantiationName,
                        NumberTest,
                        ::testing::Values(4, 6, 9));

Now let us assume I have a function std::string Number::toString(int n); and I want to test

ASSERT_EQ(nr.toString(1), "one");
ASSERT_EQ(nr.toString(2), "two");
ASSERT_EQ(nr.toString(3), "three");

Can I write this as a value parameterized test? I yes, how to specify the expected results? As far as I know JUnit expects parameter-expected_value types. Can I do something similar with Google Test?

Aucun commentaire:

Enregistrer un commentaire