Create a Utility Class in Standalone version
PROBLEM
I would like to create global variables and/or functions in Test Studio Standalone version. These variables/functions need to be accessible from all the tests within the test project.
SOLUTION
Define a utility class that will contain the intended functions/variables. This is very easy to do when you're working with the Visual Studio plugin. It's a bit trickier in the Standalone version, however.
- Create a new test.
- Add a Coded Step.
- This automatically generates a new class that has the same name as the test (this is the code-behind file).
- In the same namespace we're going to manually add a brand new class
- This will be the Utilities class. Click the View Class button to display the entire code for the namespace (the project):

- Add the Utility class within the project's namespace.
- The namespace already contains one class which was generated from the coded step of the test.
- Write your class definition in the namespace. Ensure it's within the namespace, but not inside of another class.
Let's say I want to define a class that has one integer variable and one function which writes text to a .txt file. Here's what the class definition looks like:
C#
public static class Utility
{
public static int valueHolder;
public static void writeToFile(String path,String content)
{
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter(path);
file.WriteLine(content);
file.Close();
}
}
Visual Basic
Public NotInheritable Class Utility
Private Sub New()
End Sub
Public Shared valueHolder As Integer
Public Shared Sub writeToFile(path As [String], content As [String])
' Write the string to a file.
Dim file As New System.IO.StreamWriter(path)
file.WriteLine(content)
file.Close()
End Sub
End Class
Run the test once. This builds the assembly. Then you'll be able to access the functions/variables within your Utilities class from all tests in this project. For instance, if you're using the above class definition, you can acess it like so:
C#
Utility.valueHolder = 2; //Set value
Log.WriteLine("Value from Utility class:" + Utility.valueHolder.ToString()); //Write value to test Log
Utility.writeToFile(@"c:\myNewText200.txt", "some content"); //Invoke function
Visual Basic
Utility.valueHolder = 2
'Set value
Log.WriteLine("Value from Utility class:" + Utility.valueHolder.ToString())
'Write value to test Log
Utility.writeToFile("c:\myNewText200.txt", "some content")
'Invoke function
Note that the Test Studio code editor will not autocomplete references to the contents of the utility class made in other files in the project.