Page 1 of 1

Passing Class Object between Test Cases

Posted: Tue Jul 24, 2018 10:16 pm
by shanefox
Is it possible to pass a class object between test cases?

Re: Passing Class Object between Test Cases

Posted: Wed Jul 25, 2018 9:04 am
by Stub
When I want to pass parameters between test cases - e.g. some kind of filename - I sometimes return a string value via one of the module parameters (so I'm using the module parameter as an output parameter), then feed that returned value into another test case (this time as an input parameter).

Off the top of my head, if I wanted to reference a more complex object I think I might use the string parameter that I'm passing around as a key into some kind of collection e.g. a dictionary.

Re: Passing Class Object between Test Cases

Posted: Wed Jul 25, 2018 2:41 pm
by McTurtle
Hello shanefox,

IMHO, I think that a singleton might be useful for you?
What if you create a class like this?
using System;

namespace SharingAClass
{
	public class myClass
	{
		static myClass _instance= new myClass();
		public static myClass Instance
		{
			get
			{
				return _instance;
			}
		}
		myClass()
		{
		}
		public string myVariable_one="";
		public string myVariable_two="";
	}
}
You should now be able to set and read the values from that class from anywhere in the test suite. In some random test case you could set myClass.Instance.myVariable_one="Test_one", in another one you could set myClass.Instance.myVariable_two="Test_two"; without having to declare a new instance of the class. Then again, somewhere completely different you can access them:
Report.Info(myClass.Instance.myVariable_one);
Report.Info(myClass.Instance.myVariable_two);
Is this useful to you?

Regards,
McTurtle

Re: Passing Class Object between Test Cases

Posted: Tue Aug 07, 2018 9:01 pm
by shanefox
Thanks. I will try it.