Runtime Parameters

TAEF provides functionality for passing runtime parameters to the tests it executes.

Usage

To pass a parameter to your test, supply this parameter to te.exe as a command line parameter in the following form:

Te.exe /p:ParameterName1=ParameterValue1  /p:ParameterName2=ParameterValue2

If the parameter value contains spaces, put quotes around parameter name and parameter value:

Te.exe /p:"ParameterName3=The quick brown fox jumps over the lazy dog"

Built-in Parameters

TAEF has built-in support for the following Runtime Parameters:

  • TestDeploymentDir: The test binary directory.
  • TestName: The name of the test which is currently running.
  • FullTestName: The full name of the test including variation qualifiers. This is the name as TAEF logs it for StartGroup and EndGroup.
  • TestResult: The aggregate worst-case result of tests executed within the scope of this Cleanup function. In order from best to worst: Passed, NotRun, Skipped, Blocked, Failed. For example, if at least one test in your class was blocked but no tests failed, the result will be "Blocked" (only available in Cleanup functions).

Accessing Runtime Parameters from Tests

Native Tests

Runtime Parameters are available in Setup, Cleanup and test methods. Use the RuntimeParameters::TryGetValue API to obtain them:

String value;
VERIFY_SUCCEEDED(RuntimeParameters::TryGetValue(L"ParameterName3", value));

Note: In order to request Runtime Parameters from your tests, you will need to link against Te.Common.lib library.

Managed Tests

Runtime Parameters are available in setup and test methods. To obtain them, use the TestContext property of your class.

Example (class or assembly setup):

[ClassInitialize]

public static void ClassSetup(TestContext context)
{
    String parameterName3  = context.Properties["ParameterName3"];

}

Similarly, from a test:

[TestMethod]

public void VerifyRuntimeParametersTest()
{
    String parameterName3  = m_testContext.Properties["ParameterName3"].ToString());
}

// Note, that to work with runtime parameters, as well as with your tests,  you need to add
// definition of test context property to your class

private TestContext m_testContext;

public TestContext TestContext
{
    get { return m_testContext; }
    set { m_testContext = value; }
}

Script Tests

Runtime parameters are available in the setup, cleanup and the test methods. To retrieve runtime parameters, define and instantiate the RuntimeParameters object from Te.Common:

<object id="RuntimeParameters" progid="Te.Common.RuntimeParameters" />

Once the RuntimeParameters object is instantiated, you can use RuntimeParameters.Contains("<runtime parameter name>") method to query if a runtime parameter was supplied and is available to the test. If it returns true, you can then use RuntimeParameters.GetValue("<runtime parameter name>") to retrieve it. Note that RuntimeParameters.GetValue(...) will throw if the runtime parameter is not available. The following example is from our VBScript example:

<script language="VBScript">
    <![CDATA[
        Function TestOne()
            dim param
            param = "No runtime param"
            If RuntimeParameters.Contains("param") Then
                    param = RuntimeParameters.GetValue("param")
            End If
            Log.Comment("Param is " + param)

            dim testDir
            If RuntimeParameters.Contains("testDir") Then
                testDir = RuntimeParameters.GetValue("TestDir")
            End If
            Log.Comment("The test harness is running in " + testDir)
        End Function
    ]] >
</script>