forked from qt-creator/qt-creator
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:
@@ -511,7 +511,7 @@ public:
|
|||||||
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
|
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
|
||||||
[] { return dd->m_loadProjectScenario(); });
|
[] { return dd->m_loadProjectScenario(); });
|
||||||
|
|
||||||
addTest<AutoTestUnitTests>(&dd->m_testTreeModel);
|
addTestCreator(createAutotestUnitTests);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,16 +34,40 @@ using namespace ExtensionSystem;
|
|||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
AutoTestUnitTests::AutoTestUnitTests(TestTreeModel *model, QObject *parent)
|
class AutotestUnitTests : public QObject
|
||||||
: QObject(parent),
|
|
||||||
m_model(model)
|
|
||||||
{
|
{
|
||||||
}
|
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();
|
const QList<Kit *> allKits = KitManager::kits();
|
||||||
if (allKits.count() == 0)
|
if (allKits.count() == 0)
|
||||||
@@ -80,12 +104,12 @@ void AutoTestUnitTests::initTestCase()
|
|||||||
theQtTestFramework().quickCheckForDerivedTests.setValue(true);
|
theQtTestFramework().quickCheckForDerivedTests.setValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::cleanupTestCase()
|
void AutotestUnitTests::cleanupTestCase()
|
||||||
{
|
{
|
||||||
delete m_tmpDir;
|
delete m_tmpDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParser()
|
void AutotestUnitTests::testCodeParser()
|
||||||
{
|
{
|
||||||
QFETCH(FilePath, projectFilePath);
|
QFETCH(FilePath, projectFilePath);
|
||||||
QFETCH(int, expectedAutoTestsCount);
|
QFETCH(int, expectedAutoTestsCount);
|
||||||
@@ -110,7 +134,7 @@ void AutoTestUnitTests::testCodeParser()
|
|||||||
QCOMPARE(m_model->dataTagsCount(), expectedDataTagsCount);
|
QCOMPARE(m_model->dataTagsCount(), expectedDataTagsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParser_data()
|
void AutotestUnitTests::testCodeParser_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<FilePath>("projectFilePath");
|
QTest::addColumn<FilePath>("projectFilePath");
|
||||||
QTest::addColumn<int>("expectedAutoTestsCount");
|
QTest::addColumn<int>("expectedAutoTestsCount");
|
||||||
@@ -133,7 +157,7 @@ void AutoTestUnitTests::testCodeParser_data()
|
|||||||
<< 4 << 10 << 5 << 10;
|
<< 4 << 10 << 5 << 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParserSwitchStartup()
|
void AutotestUnitTests::testCodeParserSwitchStartup()
|
||||||
{
|
{
|
||||||
QFETCH(FilePaths, projectFilePaths);
|
QFETCH(FilePaths, projectFilePaths);
|
||||||
QFETCH(QList<int>, expectedAutoTestsCount);
|
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<FilePaths>("projectFilePaths");
|
||||||
QTest::addColumn<QList<int> >("expectedAutoTestsCount");
|
QTest::addColumn<QList<int> >("expectedAutoTestsCount");
|
||||||
@@ -187,7 +211,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data()
|
|||||||
<< expectedUnnamedQuickTests << expectedDataTagsCount;
|
<< expectedUnnamedQuickTests << expectedDataTagsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParserGTest()
|
void AutotestUnitTests::testCodeParserGTest()
|
||||||
{
|
{
|
||||||
if (qtcEnvironmentVariableIsEmpty("GOOGLETEST_DIR"))
|
if (qtcEnvironmentVariableIsEmpty("GOOGLETEST_DIR"))
|
||||||
QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)");
|
QSKIP("This test needs googletest - set GOOGLETEST_DIR (point to googletest repository)");
|
||||||
@@ -226,7 +250,7 @@ void AutoTestUnitTests::testCodeParserGTest()
|
|||||||
QCOMPARE(m_model->boostTestNamesCount(), 0);
|
QCOMPARE(m_model->boostTestNamesCount(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParserGTest_data()
|
void AutotestUnitTests::testCodeParserGTest_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<FilePath>("projectFilePath");
|
QTest::addColumn<FilePath>("projectFilePath");
|
||||||
QTest::newRow("simpleGoogletest")
|
QTest::newRow("simpleGoogletest")
|
||||||
@@ -235,7 +259,7 @@ void AutoTestUnitTests::testCodeParserGTest_data()
|
|||||||
<< m_tmpDir->filePath() / "simple_gt/simple_gt.qbs";
|
<< m_tmpDir->filePath() / "simple_gt/simple_gt.qbs";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParserBoostTest()
|
void AutotestUnitTests::testCodeParserBoostTest()
|
||||||
{
|
{
|
||||||
if (!m_checkBoost)
|
if (!m_checkBoost)
|
||||||
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)");
|
||||||
@@ -281,7 +305,7 @@ void AutoTestUnitTests::testCodeParserBoostTest()
|
|||||||
QCOMPARE(m_model->gtestNamesCount(), 0);
|
QCOMPARE(m_model->gtestNamesCount(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParserBoostTest_data()
|
void AutotestUnitTests::testCodeParserBoostTest_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<FilePath>("projectFilePath");
|
QTest::addColumn<FilePath>("projectFilePath");
|
||||||
QTest::addColumn<QString>("extension");
|
QTest::addColumn<QString>("extension");
|
||||||
@@ -300,10 +324,16 @@ static int executeScenario(const QString &scenario)
|
|||||||
return QProcess::execute(data.m_executable, data.m_args + additionalArgs);
|
return QProcess::execute(data.m_executable, data.m_args + additionalArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testModelManagerInterface()
|
void AutotestUnitTests::testModelManagerInterface()
|
||||||
{
|
{
|
||||||
QCOMPARE(executeScenario("TestModelManagerInterface"), 0);
|
QCOMPARE(executeScenario("TestModelManagerInterface"), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
QObject *createAutotestUnitTests()
|
||||||
} // namespace Autotest
|
{
|
||||||
|
return new AutotestUnitTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Autotest::Internal
|
||||||
|
|
||||||
|
#include "autotestunittests.moc"
|
||||||
|
@@ -5,43 +5,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace CppEditor { namespace Tests { class TemporaryCopiedDir; } }
|
namespace Autotest::Internal {
|
||||||
namespace ProjectExplorer { class Kit; }
|
|
||||||
|
|
||||||
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
|
} // namespace Autotest
|
||||||
|
Reference in New Issue
Block a user