mardi 5 juillet 2016

How to run several test cases for one fixture in google test?

Supose i have Google Test fixture named ProfileTest inherited from ::testing::TestWithParams<T> that creates a parser.

class ProfileTest: public ::testing::TestWithParam<std::tuple<std::string,std::string>>{

public:
    QString getName(){
        return QFileInfo(*m_file).fileName();
    }

protected:
    void SetUp(){

        m_profile = new Profile();

        m_file = new QFile(std::get<0>(GetParam()).c_str());
        m_file->open(QIODevice::WriteOnly | QIODevice::Text);
        m_file->write(std::get<1>(GetParam()).c_str());
        m_file->close();

    }
    void TearDown(){

        delete m_file;

        delete m_profile;
    }

    Profile* m_profile;
    QFile *m_file;
};

also i have parametrized test case

TEST_P(ProfileTest, TestProfileGoodFormedContent){
    ASSERT_NO_THROW(m_profile->readProfile(QFileInfo(*m_file)));
    ASSERT_STREQ(m_profile->name(), getName());
    ASSERT_GE(m_profile->getProfileConfigurations().size(),1);
}

I have added TEST_CASE with well-formed content, and anything works great.

Now I want to add TEST_CASE with bad-formed content, but TestProfileGoodFormedContent TEST_P unsuitable for testing bad content.

I suppose i should to add new TEST_P but it will have same fixture(ProfileTest), that brings me an error that all test cases will we provided to any TEST_P that have ProfileTest as fixture.

What should i do, to test well-formed content and bad-formed content simultaneously?

Aucun commentaire:

Enregistrer un commentaire