Yats – Test Case Parameters

By | March 26, 2013

This article will show how parameters are implemented in a test case.

The Yats framework uses .NET Reflection to find out and configure the parameters of a test case. When a test case is written for the Native Yats test repository, the following rules apply:

  • A test case parameter is a public class property that has both a public getter and setter. For example:

public class MyTestCase: IYatsTestCase

{

...

protected string stringParameter;
public string StringParameter
{
get {return stringParameter;}
set {stringParameter = value;}
}

  • If a public property has a Getter but not a Setter, it is considered to be a Result. A test case result can be used in other test cases. For example, one test case reads a value from a device and stores it into a result. Another test case is then configured to take the value as a parameter and analyzes it;
  • A test sequence is only allowed to be executed when all mandatory parameters are configured;
  • If a parameter is of a .NET non-nullable type (int, DateTime etc.), it must be configured;
  • nullable parameter (int?, Nullable<int>) is not mandatory;
  • For regular classes, the parameters are mandatory. In order to mark such parameter as optional, the [CanBeNull] attribute is used:

protected List<string> stringList;
[CanBeNull]
public List<string> StringListParameter
{
get { return stringList; }
set { stringList = value; }
}

  • During execution, static parameters are assigned just before the test case is run. Parameters that are linked to another test result are assigned immediately when the test finished. This allows for a parallel test to gather multiple results from other test cases or be woken up by a result;
  • If the test case declares a default parameter value in parameter declaration or default constructor, the value may be used in the editor to quickly assign or reset the parameters (see Parameter Editor. TODO: link).

The reflection mechanism in the Yats framework tries to match parameter types and if possible, convert them silently. For example, one test case declares a string result while another expects a string[] parameter. The test sequence editor allows assigning the result to the parameter and during execution an array with a single item is created and assigned. The opposite assignment is not allowed since it is not clear how to convert multiple items into one value.

Test parameter types are associated with editor controls during program start. Many built-in .NET types are supported. Another article will show how to add support for custom type parameters

Leave a Reply

Your email address will not be published.