static vs non static method in the method for business functionality

Class library usage, coding and language questions.
Ajay
Posts: 1
Joined: Mon May 09, 2022 5:43 pm

static vs non static method in the method for business functionality

Post by Ajay » Mon May 09, 2022 5:58 pm

Hi All,

What is the preference for using the nonstatic/static method to code the business functionality in C# Ranorex?


Thanks,
Ajay

csaszi89
Posts: 41
Joined: Mon Jan 17, 2022 12:10 pm

Re: static vs non static method in the method for business functionality

Post by csaszi89 » Tue Aug 30, 2022 11:41 am

Hi,

I do not know such common preferences. It depends on the goal you want to achieve.
A static member exists until the app domain unloads (the windows process closed), a non-static member exists until its creation context exists, after that it gets simply "garbage-collected" by the GC.
Based on this, you have to decide to use static or non-static members.
For example, lets assume I have 10 tests. Each tests use a simulator to simulate some test data. The simulator must be initialized before the first use, but it is not needed to initialize it again test by test. So, I want to achieve that the simulator is initialized only once and before the first test.
This is the case where you should decide to use static members. Creating a static Simulator with some static methods would be beneficial.
When tester clicks Run button in Ranorex then it will create the app domain (only one process will be created for the 10 tests), and the static members will be initialized, and all tests can access them.

Best regards,
Gyuri