Testcase Item

class Testcase

Implements a test action.

Locations:Project, document root
Nested items:Component, Depends, Exports, Matrix
Enumerations:Result
Properties:dependencies, elapsedTime, name, result, workingDirectory
Methods:run(),
Signals:created(), destruction(), finished(), started()

Detailed Description

A Testcase component combines probes, constraints and other QML components into a single test case. It is executed as one atomic entity. Every test case must have a unique name throughout the project and must implement a run() method.

Example:

import qst 1.0

Testcase {
    name: "test-myprocess"

    ProcessProbe {
        id: process
        command: "/usr/bin/echo"
        arguments: [
            "Hello World"
        ]
    }

    function run() {
        process.start();
        process.waitForFinished(100);
        Qst.compare(process.readAllStandardOutput(), "Hello World");
        // Testcase will finish with result 'Pass'
    }
}

Enumerations

enum Result

The outcome of the test case execution. The default value after start is Unfinished. The result changes to Fail when the first evaluation statement fails or otherwise it is set to Pass when the run() method completes without any issue.

enumerator Unfinished

Default value after start.

enumerator Pass

The method run() has finished without any issue.

enumerator Fail

An error occured or one of the constraints has failed while executing run().

Properties

var dependencies

When the test case contains a Depends items, this property makes exported values for every dependency name or alias accessible. Data forwarded by Exports can be accessed in bindings and code. Dependencies are always attached in list form beause a test case might be represented by multiple jobs:

simple-exports.qml
        Depends {
            name: "A"
        }
        function run() {
            Qst.info("A was " + dependencies.A[0].result)
        }

This property is read-only.

uint64 elapsedTime

Time in milliseconds since the test case was started.

This property is updated on every read access and cannot be used as a binding.

string name

Identifier for this test case. This property must be a plain string and must be unique across the whole project.

The default value is an empty string.

Result result

The outcome of a test case run. The default value is Result::Unfinished.

const string workingDirectory

A unique directory where the current test case and child components may store files. The directory may be used for log files or as scratch pad and is always created on execution start.

The default value is project.workingDirectory + "/" + name and cannot be changed by the test case.

Methods

void run()

Contains the execution code and is called when the test case starts. It has to be implemented by the user. The run() method may contain several other blocking calls to methods and functions. It will return only for two reasons:

  1. All statements have been executed. result will be set to Result::Pass.
  2. An error has occurred or a constraint has failed and result has been set to Result::Fail. In that case, all remaining statements are aborted.

Signals

void created()

This signal is emitted after the destruction() signal of the previous Testcase and before started() of the current one. It is the QML way of implementing a constructor and can be used to initialize resources.

The signal is also attached to every Component as Testcase.created().

void destruction()

This signal is emitted before the Testcase component is physically destroyed and may be used to free up resources.

The signal is also attached to every Component as Testcase.destruction().

void finished()

This signal is emitted after the run() function has returned and may be used for final evaluation or cleaning up. By that time, result may not have been set, yet and thus, it is still allowed to call verification functions.

The signal is also attached to every Component as Testcase.finished().

void started()

This signal is emitted after created() and before run() is invoked. It may be used for starting concurrent activities.

The signal is also attached to every Component as Testcase.started().