Defaults and references

Defaults and references are a generic case of the feature about Manage connection strings. The goal of these features is to avoid repetition of common values for all (or a part) of your tests. You write them at one place (in the settings element) and these values will be applied in each of your tests. The big advantage is the centralization: in case you need to adapt these values, you'll have to change them at a unique place and not everywhere in your test-suite.

The difference between the two concepts is that a default will inject an information into your test if no value is provided for this information by your test. If a value is provided for this information, the default will be ignored. A reference must be explicitly called from your test. If you don't call the reference from your test, the value of this information will not be used in your test.

Default

Scope

A default must be associated to a scope. This scope delimits where this default value will be applicable. The valid choices are:
  • everywhere
  • system-under-test
  • assert
  • setup-cleanup
If a default is specified for the scope everywhere and for any other scope, the value of everywhere will be overridden by the value provided for the specific scope. This let you define an applicable value for assert and system-under-test but another applicable value specific to the scope setup-cleanup by defining a default for everywhere and another for setup-cleanup.

Values configurable in a default

There are four kind of values configurable in a default section. The first one is the connection-string applicable to the tests, more information is available in Manage connection strings.

In addition, you can also configure values for Query's parameters and Query's template-variables used in Sql and Mdx queries. Note that the sql-type of a parameter can be changed when you're overriding it in a scope. In addition to override the default value of a parameter in a more limited scope, you can always override the parameter for a specific test by defining a value inside the test.

New in version 1.9, the last kind of information that you can define in a default is information about reports and more precisely the attributes source and the path. These information will be used in all your tests, except if overridden by a reference or by a value provided with the test.
<settings>
    <default apply-to="...">
        <report
             source="http://reporting.com/reports"
             path="Dashboards"
         />
    </default>
</settings>

The sample here under configures values for a connection-string that will be used everywhere except in system-under-test where another value is provided. A parameter named paramEverywhere will also be used in both system-under-test and assertions, the second parameter named paramToOverride will also have a different values in the system-under-test and assertion.

<settings>
    <default apply-to="everywhere">
        <connectionString>My Connection String from Everywhere</connectionString>
        <parameter name="paramEverywhere">120</parameter>
        <parameter name="paramToOverride" sql-type="Int">60</parameter>
    </default>
    <default apply-to="system-under-test">
        <connectionString>My Connection String</connectionString>
        <parameter name="paramToOverride" sql-type="varchar(10)">Alpha</parameter>
    </default>
</settings>

In the following test, the values Alpha, 120 and My Connection String (defined in the settings above) will be used to execute the query defined in the system-under-test.

<test name="My first test case" uid="0001">
    <system-under-test>
        <execution>
            <query name="Select first product">
                    SELECT * FROM Product Where FieldOne=@paramToOverride and FieldTwo<>@paramEverywhere;
            </query>
        </execution>
    </system-under-test>
    <assert>
         ...
    </assert>
</test>

Reference

A reference is different than a default because it must be explicitly referenced in the test. In the sample above, we've never explicitly said to NBi that we want to use the values provided into the default element: it was automatic. On the other hand, by using only defaults, it's impossible for us to define two values for the connection-strings, one used for the first fifty tests and the other one used for the last twenty. A reference is there to manage these cases.

When creating a reference, you're defining a name that will be used in your test to specify which reference needs to be used in this test. In the test, you must use the symbol @ to specify that the value must come from reference.

The sample here under creates two references named first-ref and second-ref and the test defined under them calls the value from the reference second-ref.
<settings>
    <reference name="first-ref">
        <connectionString>My First Connection String</connectionString>
    </reference>
    <reference name="second-ref">
        <connectionString>My Second Connection String</connectionString>
    </reference>
</settings>
<test name="My first test case" uid="0001">
    <system-under-test>
        <execution>
            <query name="Select first product" connectionString="@second-ref">
                SELECT TOP 2 * FROM Product;
            </query>
        </execution>
    </system-under-test>
    <assert>
    ...
    </assert>
</test>

Values configurable in a reference

In a reference you can configure values for
  • connection-string (more info in Manage connection strings)
  • Report (Source and Path) Added in version 1.9
  • regex
  • numeric-format
  • currency-format

Last edited Dec 27, 2014 at 12:43 PM by Seddryck, version 4

Comments

No comments yet.