Commit 4f7eb4e6 authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

Plugin Tests: Support additional test objects/classes

So far tests running within Qt Creator could be implemented with a
private slot in the plugin class starting with "test".

Binding the test functions to the plugin object/class is fine for test
functions without side effects. But as soon as side effects come into
play we need proper initialization and cleanup as it's provided by
init(), cleanup(), initTestCase() and cleanupTestCase(). However,
implementing these functions in the plugin class is not appropriate
since they would affect (potentially quite diverse) test functions.

This patch enables us to provide 'ordinary' test classes in which we can
handle initialization and clean up the usual way.

In addition to the current test invocations, e.g.:

    # (1) Run all test functions of the plugin
    ./qtcreator -test CppTools

    # (2) Run selected test functions of the plugin by stating them
    ./qtcreator -test CppTools,test_completion,test_builtinsymbolsearcher

    # (3) Run selected test functions of the plugin by a wild card
    # expression
    ./qtcreator -test "CppTools,*pointerdeclaration*"

    # (4) Run a test function of the plugin with certain test data
    ./qtcreator -test CppTools,test_completion:template_1

it's now also possible to state the test class in order to execute all
test functions of that class:

    # Run all test functions of a certain class:
    ./qtcreator -test CppTools,SomeClassWithTests

As long as the test class does not start with "test", there should not
be any problems.

Further, an invocation like (1) now additionally execute all test
functions of all test classes. For invocations of type (2), (3) and (4)
all test functions of all test classes are considered, too.

Change-Id: Ief08a6e9e451c599fd0109b8b8e57f92e3ee19f2
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 2992653a
......@@ -204,6 +204,20 @@ IPlugin::~IPlugin()
d = 0;
}
/*!
\fn QList<QObject *> IPlugin::createTestObjects() const
Returns objects that are meant to be passed on to QTest::qExec().
This function will be called if the user starts \QC with '-test PluginName' or '-test all'.
The ownership of returned objects is transferred to caller.
*/
QList<QObject *> IPlugin::createTestObjects() const
{
return QList<QObject *>();
}
/*!
\fn PluginSpec *IPlugin::pluginSpec() const
Returns the PluginSpec corresponding to this plugin.
......
......@@ -64,6 +64,7 @@ public:
virtual bool delayedInitialize() { return false; }
virtual ShutdownFlag aboutToShutdown() { return SynchronousShutdown; }
virtual QObject *remoteCommand(const QStringList & /* options */, const QStringList & /* arguments */) { return 0; }
virtual QList<QObject *> createTestObjects() const;
PluginSpec *pluginSpec() const;
......
This diff is collapsed.
......@@ -83,10 +83,10 @@ public:
class TestSpec {
public:
TestSpec(PluginSpec *pluginSpec, const QStringList &testFunctions = QStringList())
: pluginSpec(pluginSpec), testFunctions(testFunctions) {}
TestSpec(PluginSpec *pluginSpec, const QStringList &testFunctionsOrObjects = QStringList())
: pluginSpec(pluginSpec), testFunctionsOrObjects(testFunctionsOrObjects) {}
PluginSpec *pluginSpec;
QStringList testFunctions;
QStringList testFunctionsOrObjects;
};
bool containsTestSpec(PluginSpec *pluginSpec) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment