Autotest: Move unit plugin test creation closer to the tested code

The current pattern.

Change-Id: I52354584734755b3b0f3d2c9596801dc050300fc
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-19 12:25:23 +01:00
parent f9f43f7492
commit 45bb4a5f76
3 changed files with 52 additions and 57 deletions

View File

@@ -511,7 +511,7 @@ public:
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
[] { return dd->m_loadProjectScenario(); });
addTest<AutoTestUnitTests>(&dd->m_testTreeModel);
addTestCreator(createAutotestUnitTests);
#endif
}

View File

@@ -34,16 +34,40 @@ using namespace ExtensionSystem;
using namespace ProjectExplorer;
using namespace Utils;
namespace Autotest {
namespace Internal {
namespace Autotest::Internal {
AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent)
: QObject(parent),
m_model(model)
class AutotestUnitTests : public QObject
{
}
Q_OBJECT
void AutoTestUnitTests::initTestCase()
public:
AutotestUnitTests()
: m_model(TestTreeModel::instance())
{}
private slots:
void initTestCase();
void cleanupTestCase();
void testCodeParser();
void testCodeParser_data();
void testCodeParserSwitchStartup();
void testCodeParserSwitchStartup_data();
void testCodeParserGTest();
void testCodeParserGTest_data();
void testCodeParserBoostTest();
void testCodeParserBoostTest_data();
void testModelManagerInterface();
private:
TestTreeModel *m_model = nullptr;
CppEditor::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
bool m_isQt4 = false;
bool m_checkBoost = false;
ProjectExplorer::Kit *m_kit = nullptr;
};
void AutotestUnitTests::initTestCase()
{
const QList<Kit *> allKits = KitManager::kits();
if (allKits.count() == 0)
@@ -80,12 +104,12 @@ void AutoTestUnitTests::initTestCase()
theQtTestFramework().quickCheckForDerivedTests.setValue(true);
}
void AutoTestUnitTests::cleanupTestCase()
void AutotestUnitTests::cleanupTestCase()
{
delete m_tmpDir;
}
void AutoTestUnitTests::testCodeParser()
void AutotestUnitTests::testCodeParser()
{
QFETCH(FilePath, projectFilePath);
QFETCH(int, expectedAutoTestsCount);
@@ -110,7 +134,7 @@ void AutoTestUnitTests::testCodeParser()
QCOMPARE(m_model->dataTagsCount(), expectedDataTagsCount);
}
void AutoTestUnitTests::testCodeParser_data()
void AutotestUnitTests::testCodeParser_data()
{
QTest::addColumn<FilePath>("projectFilePath");
QTest::addColumn<int>("expectedAutoTestsCount");
@@ -133,7 +157,7 @@ void AutoTestUnitTests::testCodeParser_data()
<< 4 << 10 << 5 << 10;
}
void AutoTestUnitTests::testCodeParserSwitchStartup()
void AutotestUnitTests::testCodeParserSwitchStartup()
{
QFETCH(FilePaths, projectFilePaths);
QFETCH(QList<int>, expectedAutoTestsCount);
@@ -161,7 +185,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup()
}
}
void AutoTestUnitTests::testCodeParserSwitchStartup_data()
void AutotestUnitTests::testCodeParserSwitchStartup_data()
{
QTest::addColumn<FilePaths>("projectFilePaths");
QTest::addColumn<QList<int> >("expectedAutoTestsCount");
@@ -187,7 +211,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data()
<< expectedUnnamedQuickTests << expectedDataTagsCount;
}
void AutoTestUnitTests::testCodeParserGTest()
void AutotestUnitTests::testCodeParserGTest()
{
if (qtcEnvironmentVariableIsEmpty("GOOGLETEST_DIR"))
QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)");
@@ -226,7 +250,7 @@ void AutoTestUnitTests::testCodeParserGTest()
QCOMPARE(m_model->boostTestNamesCount(), 0);
}
void AutoTestUnitTests::testCodeParserGTest_data()
void AutotestUnitTests::testCodeParserGTest_data()
{
QTest::addColumn<FilePath>("projectFilePath");
QTest::newRow("simpleGoogletest")
@@ -235,7 +259,7 @@ void AutoTestUnitTests::testCodeParserGTest_data()
<< m_tmpDir->filePath() / "simple_gt/simple_gt.qbs";
}
void AutoTestUnitTests::testCodeParserBoostTest()
void AutotestUnitTests::testCodeParserBoostTest()
{
if (!m_checkBoost)
QSKIP("This test needs boost - set BOOST_INCLUDE_DIR (or have it installed)");
@@ -281,7 +305,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
QCOMPARE(m_model->gtestNamesCount(), 0);
}
void AutoTestUnitTests::testCodeParserBoostTest_data()
void AutotestUnitTests::testCodeParserBoostTest_data()
{
QTest::addColumn<FilePath>("projectFilePath");
QTest::addColumn<QString>("extension");
@@ -300,10 +324,16 @@ static int executeScenario(const QString &scenario)
return QProcess::execute(data.m_executable, data.m_args + additionalArgs);
}
void AutoTestUnitTests::testModelManagerInterface()
void AutotestUnitTests::testModelManagerInterface()
{
QCOMPARE(executeScenario("TestModelManagerInterface"), 0);
}
} // namespace Internal
} // namespace Autotest
QObject *createAutotestUnitTests()
{
return new AutotestUnitTests;
}
} // namespace Autotest::Internal
#include "autotestunittests.moc"

View File

@@ -5,43 +5,8 @@
#include <QObject>
namespace CppEditor { namespace Tests { class TemporaryCopiedDir; } }
namespace ProjectExplorer { class Kit; }
namespace Autotest::Internal {
namespace Autotest {
QObject *createAutotestUnitTests();
class TestTreeModel;
namespace Internal {
class AutoTestUnitTests : public QObject
{
Q_OBJECT
public:
explicit AutoTestUnitTests(TestTreeModel *model, QObject *parent = nullptr);
signals:
private slots:
void initTestCase();
void cleanupTestCase();
void testCodeParser();
void testCodeParser_data();
void testCodeParserSwitchStartup();
void testCodeParserSwitchStartup_data();
void testCodeParserGTest();
void testCodeParserGTest_data();
void testCodeParserBoostTest();
void testCodeParserBoostTest_data();
void testModelManagerInterface();
private:
TestTreeModel *m_model = nullptr;
CppEditor::Tests::TemporaryCopiedDir *m_tmpDir = nullptr;
bool m_isQt4 = false;
bool m_checkBoost = false;
ProjectExplorer::Kit *m_kit = nullptr;
};
} // namespace Internal
} // namespace Autotest