jeudi 20 décembre 2018

How can I customize Google Test failure messages?

I've written a Google Test like the one below which compares some computed values with the one expected stored in a CSV file.

class SampleTest : public ::testing::Test{
public:

    void setupFile(const std::string& filename) {
       // open csv file here
    }

    void checkRow(ComputedRowValue val) {
        CSVParsedOutput out;
        m_csv_f.readAndParseLine(out);
        EXPECT_EQ(out.field1, val.field1);
        EXPECT_EQ(out.field2, val.field2);
        EXPECT_EQ(out.field3, val.field3);
        m_csv_line++;
    }


protected:
    CSVFile m_csv_f; // CSV file with expected results
    int m_csv_line = 0;
};

This is going to be running across some huge file sizes and EXPECT_EQ when failing will only tell me which value mismatches. How can I override the error message output by EXPECT_EQ to also print m_csv_line?

Aucun commentaire:

Enregistrer un commentaire