This is a migrated thread and some comments may be shown as answers.

Global Vars in C#

1 Answer 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rakesh
Top achievements
Rank 1
Rakesh asked on 27 Aug 2012, 07:57 PM

I would like to have global variables which can be used across tests in current project.
In the project namespace, I creates a static class with the global vars (along with accessor methods).
But I was not able to use these vars, error seen while running tests stating: class does not contain definition for var.
I am not so familar with C#, but I tried other solution as well: created a struct inside the static class,
which includes the global vars. But in this case, I was not able to access the struct vars.
Value types for some reason cant be accessed the way we expected global vars to ber accessed.
I cant acess value types globally but for some reason I can acess reference types.

Any ideas or workaround on creating global vars - which can be set/get accross different classes/tests in Telerik?

Thanks,
Rakesh

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 30 Aug 2012, 07:13 PM
Hi,

Creating a static class should work just fine. Here's an example of a static class that can be used:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace MySampleTests
{
    static class MyStaticClass
    {
        public static string GetCompanyName() { return "CompanyName"; }
        public static string GetCompanyAddress() { return "CompanyAddress"; }
    }
}

Now in the test code you reference/use the members like this:
string name = MyStaticClass.GetCompanyName();

Hope that helps!

Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Rakesh
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or