aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/imports/testlib/TestCase.qml7
-rw-r--r--src/imports/testlib/testcase.qdoc25
2 files changed, 26 insertions, 6 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 1f9de5e998..694c01a710 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -475,6 +475,7 @@ Item {
function cleanupTestCase() {}
function init() {}
function cleanup() {}
+ function init_data() {}
function qtest_runInternal(prop, arg) {
try {
@@ -607,6 +608,10 @@ Item {
functionsToRun.splice(index, 1)
}
qtest_results.functionName = prop
+
+ if (!testCase.hasOwnProperty(datafunc))
+ datafunc = "init_data";
+
if (datafunc in testCase) {
if (qtest_runInternal(datafunc)) {
var table = qtest_testCaseResult
@@ -624,7 +629,7 @@ Item {
qtest_runFunction(prop, row)
qtest_results.dataTag = ""
}
- if (!haveData)
+ if (!haveData && datafunc != "init_data")
qtest_results.warn("no data supplied for " + prop + "() by " + datafunc + "()"
, util.callerFile(), util.callerLine());
qtest_results.clearTestTable()
diff --git a/src/imports/testlib/testcase.qdoc b/src/imports/testlib/testcase.qdoc
index f928cdaa44..29f7a2d287 100644
--- a/src/imports/testlib/testcase.qdoc
+++ b/src/imports/testlib/testcase.qdoc
@@ -51,8 +51,8 @@
element:
\code
- import QtQuick 1.0
- import QtQuickTest 1.0
+ import QtQuick 2.0
+ import QtTest 1.0
TestCase {
name: "MathTests"
@@ -97,15 +97,24 @@
\section1 Data-driven tests
Table data can be provided to a test using a function name that ends
- with "_data":
+ with "_data". Alternatively, the \c init_data() function can be used
+ to provide default test data for all test functions in a TestCase element:
+
\code
- import QtQuick 1.0
- import QtQuickTest 1.0
+ import QtQuick 2.0
+ import QtTest 1.0
TestCase {
name: "DataTests"
+ function init_data() {
+ return [
+ {tag:"init_data_1", a:1, b:2, answer: 3},
+ {tag:"init_data_2", a:2, b:4, answer: 6}
+ ];
+ }
+
function test_table_data() {
return [
{tag: "2 + 2 = 4", a: 2, b: 2, answer: 4 },
@@ -114,6 +123,12 @@
}
function test_table(data) {
+ //data comes from test_table_data
+ compare(data.a + data.b, data.answer)
+ }
+
+ function test__default_table(data) {
+ //data comes from init_data
compare(data.a + data.b, data.answer)
}
}