AutoTest: Fix flakyness of plugin test

Relying on the order of tests of the underlying tree
model is bad as we order the model for the user with a
QSortFilterProxyModel.
Using non-unique keys is not wise either.
Ensure the keys are unique to have reliable results.

Change-Id: I556371d018c16e7b03a8ec85d60afc850056a94a
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-03-25 16:29:04 +01:00
parent 9414961206
commit ca82019cf0
3 changed files with 24 additions and 13 deletions

View File

@@ -246,6 +246,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)"); QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)");
QFETCH(QString, projectFilePath); QFETCH(QString, projectFilePath);
QFETCH(QString, extension);
CppTools::Tests::ProjectOpenerAndCloser projectManager; CppTools::Tests::ProjectOpenerAndCloser projectManager;
CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
QVERIFY(projectInfo.isValid()); QVERIFY(projectInfo.isValid());
@@ -257,14 +258,23 @@ void AutoTestUnitTests::testCodeParserBoostTest()
QCOMPARE(m_model->boostTestNamesCount(), 5); QCOMPARE(m_model->boostTestNamesCount(), 5);
QMultiMap<QString, int> expectedSuitesAndTests; QString basePath;
expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 2); // decorators w/o suite if (auto project = projectInfo.project())
expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 2); // fixtures basePath = project->projectFilePath().toFileInfo().absolutePath();
expectedSuitesAndTests.insert(QStringLiteral("Master Test Suite"), 3); // functions QVERIFY(!basePath.isEmpty());
expectedSuitesAndTests.insert(QStringLiteral("Suite1"), 4);
expectedSuitesAndTests.insert(QStringLiteral("SuiteOuter"), 5); // 2 sub suites + 3 tests
QMultiMap<QString, int> foundNamesAndSets = m_model->boostTestSuitesAndTests(); QMap<QString, int> expectedSuitesAndTests;
auto pathConstructor = [basePath, extension](const QString &name, const QString &subPath) {
return QString(name + '|' + basePath + subPath + extension);
};
expectedSuitesAndTests.insert(pathConstructor("Master Test Suite", "/tests/deco/deco"), 2); // decorators w/o suite
expectedSuitesAndTests.insert(pathConstructor("Master Test Suite", "/tests/fix/fix"), 2); // fixtures
expectedSuitesAndTests.insert(pathConstructor("Master Test Suite", "/tests/params/params"), 3); // functions
expectedSuitesAndTests.insert(pathConstructor("Suite1", "/tests/deco/deco"), 4);
expectedSuitesAndTests.insert(pathConstructor("SuiteOuter", "/tests/deco/deco"), 5); // 2 sub suites + 3 tests
QMap<QString, int> foundNamesAndSets = m_model->boostTestSuitesAndTests();
QCOMPARE(expectedSuitesAndTests.size(), foundNamesAndSets.size()); QCOMPARE(expectedSuitesAndTests.size(), foundNamesAndSets.size());
for (const QString &name : expectedSuitesAndTests.keys()) for (const QString &name : expectedSuitesAndTests.keys())
QCOMPARE(expectedSuitesAndTests.values(name), foundNamesAndSets.values(name)); QCOMPARE(expectedSuitesAndTests.values(name), foundNamesAndSets.values(name));
@@ -280,10 +290,11 @@ void AutoTestUnitTests::testCodeParserBoostTest()
void AutoTestUnitTests::testCodeParserBoostTest_data() void AutoTestUnitTests::testCodeParserBoostTest_data()
{ {
QTest::addColumn<QString>("projectFilePath"); QTest::addColumn<QString>("projectFilePath");
QTest::addColumn<QString>("extension");
QTest::newRow("simpleBoostTest") QTest::newRow("simpleBoostTest")
<< QString(m_tmpDir->path() + "/simple_boost/simple_boost.pro"); << QString(m_tmpDir->path() + "/simple_boost/simple_boost.pro") << QString(".pro");
QTest::newRow("simpleBoostTestQbs") QTest::newRow("simpleBoostTestQbs")
<< QString(m_tmpDir->path() + "/simple_boost/simple_boost.qbs"); << QString(m_tmpDir->path() + "/simple_boost/simple_boost.qbs") << QString(".qbs");
} }
} // namespace Internal } // namespace Internal

View File

@@ -615,13 +615,13 @@ int TestTreeModel::boostTestNamesCount() const
return rootNode ? rootNode->childCount() : 0; return rootNode ? rootNode->childCount() : 0;
} }
QMultiMap<QString, int> TestTreeModel::boostTestSuitesAndTests() const QMap<QString, int> TestTreeModel::boostTestSuitesAndTests() const
{ {
QMultiMap<QString, int> result; QMap<QString, int> result;
if (TestTreeItem *rootNode = boostTestRootNode()) { if (TestTreeItem *rootNode = boostTestRootNode()) {
rootNode->forFirstLevelChildren([&result](TestTreeItem *child) { rootNode->forFirstLevelChildren([&result](TestTreeItem *child) {
result.insert(child->name(), child->childCount()); result.insert(child->name() + '|' + child->proFile(), child->childCount());
}); });
} }
return result; return result;

View File

@@ -71,7 +71,7 @@ public:
int gtestNamesCount() const; int gtestNamesCount() const;
QMultiMap<QString, int> gtestNamesAndSets() const; QMultiMap<QString, int> gtestNamesAndSets() const;
int boostTestNamesCount() const; int boostTestNamesCount() const;
QMultiMap<QString, int> boostTestSuitesAndTests() const; QMap<QString, int> boostTestSuitesAndTests() const;
#endif #endif
void markAllForRemoval(); void markAllForRemoval();