It is possible to run Unity script driven tests using the HierarchyPath plugin. By following a set structure, test methods can be run via HPath and even pull data from the config file and return results to the source of the HierarchyPath query.


In order for a method to be called via the HPath plugin, it must use one of the two method signatures showb below, in which it takes an IEnumberable object as it's first parameter, and optionally a string as the parameter, and must return an IEnumberable object, even if just an empty list (Note: Returning a null value will result in failure).


IEnumerable<object> Method(IEnumerable<object> list, string arg1)
IEnumerable<object> Method(IEnumerable<object> list)

Once the class method has been properly constructed it can be called as an HierarchyPath function, using the standard HPath function prefix 'fn:' in the form of the following, in which the bracketed sections are replaced with the class name and method name respectively: "fn:[ClassName].[MethodName]()". The simplest way to directly run an HPath function is via the HierarchyPath debugger.



Loading Test Data from Config

Data can be loaded from the GameDriver agent config file to be used in the test methods. To do so, the data must be added to the <config> section of the file, structured like the following example:

<datatest>
  <string>stringValue</string>
  <bool>true</bool>
  <float>0.1</float>
  <floatPercent>5.0%</floatPercent>
  <floatArray>0.1,0.2,0.3</floatArray>
  <int>99</int>
  <intArray>1,2,3</intArray>
</datatest>

 Data established within the config file in this way can then be accessed in your Unity script test methods using the GameDriver agent's config helper utility. The following script is an example of how the previous sample data could be accessed from within the test script method and used to validate the test.

public class HPathPlugin
{
    public static IEnumerable<object> RunTest(IEnumerable<object> objects)
    {
        string stringResult = string.Empty;
        bool boolResult = false;
        float floatResult = 0.0f;
        float floatPercentResult = 0.0f;
        float[] floatArrayResult = new float[0];
        int intResult = 0;
        int[] intArrayResult = new int[0];
        
        stringResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/string", ""); // string
        boolResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/bool", false); // bool
        floatResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/float", 0.0f); // float
        floatPercentResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/floatPercent", 0.0f); // float
        floatArrayResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/floatArray", new float[0] ); // float[]
        intResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/int", 0); // int
        intArrayResult = gdio.unity_agent.Utilties.ConfigHelper.GetConfigItemValueOrDefault("/config/datatest/intArray", new int[0]); // int[]

        if (stringResult.Equals(""))
            Debug.LogError("String test failed.");

        if (boolResult == false)
            Debug.LogError("Bool test failed.");

        if (floatResult == 0.0f)
            Debug.LogError("Float test failed.");

        if (floatPercentResult == 0.0f)
            Debug.LogError("Float test failed.");

        if (floatArrayResult.Length == 0)
            Debug.LogError("Float Array test failed");

        if (intResult == 0)
            Debug.LogError("Int test failed.");

        if (intArrayResult.Length == 0)
            Debug.LogError("Int Array test failed");

        Debug.Log("HPathPlugin.RunTest() -> COMPLETE");

        return new object[0];
    }
}