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

Object creation while calling methods from another class.

3 Answers 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SD
Top achievements
Rank 1
SD asked on 21 Jun 2010, 08:47 AM
Hi Nelson (Thought I'd address you as you're familiar with the issue...;-))

As you recall, I'm calling helper methods from another Class the resides in another file from my [Test] and that's working well. 
The thing is, I don't want to create a large number of objects each for each test as I'm doing now (See below)...
Placing the new object statements under the class (Meaning outside the  [Test])  does not work either...Any ideas ? 

  [Test] 
            public void test_01() 
            { 
                Users Users = new Users(Manager); 
                Navigate Navigate = new Navigate(Manager); 
                Generic Generic = new Generic(Manager); 
                Register_App Register_App = new Register_App(Manager); 
                //-------------- 
                Navigate.Navigate_Basic_LogIn("tester38"); 
            } 

Ta, 
SD. 

3 Answers, 1 is accepted

Sort by
0
Missing User
answered on 23 Jun 2010, 11:22 PM
Hello SD,

I'm not sure I exactly remember what is happening with this scenario, but I would think you can try adding static class helpers for some functionality. Other than that, I would need a bit more context of what the code you posted is doing.

And are you doing a large number of dynamic object creation or are the objects manipulating alot of different test resources(ie browsers, Desktop, etc.)?
 
If your doing explicit object creation like in the code posted below, I would not think that this would be too resource intensive and degrade performance.

Sincerely,
Nelson Sin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
SD
Top achievements
Rank 1
answered on 25 Jun 2010, 01:19 AM
Hi Nelson,

I fully agree to that. Explicitly creating those objects should not have any effect on performance.  
However, it is essential to maintain code clarity as I'm creating a very large number of test and in most likelihood, 
almost all use those objects to use help methods. 

Here's what I'm doing: 
    [Test] 
            public void test_01() 
            { 
                Users Users = new Users(Manager); 
                Navigate Navigate = new Navigate(Manager); 
                Generic Generic = new Generic(Manager); 
                Register_App Register_App = new Register_App(Manager); 
                //-------------------- 
                Navigate.Navigate_Basic_LogIn(Users.MyUser); 
             } 
and the helper.....
public class Navigate : BaseTest  
    {  
        private Manager _manager = null;  
 
        private new Manager Manager  
        {  
            set 
            {  
                _manager = value;  
            }  
     
            get 
            {  
                return _manager;  
            }  
        }  
     
        public Navigate(Manager m)  
        {  
            Manager = m;  
        }      
        //************************************************** 
        // Login 
        //************************************************** 
        public void Navigate_Basic_LogIn (String user)  
        { 
          Manager.LaunchNewBrowser(Settings.Current.DefaultBrowser); 
          Manager.SetNewBrowserTracking(true); 
          Manager.ActiveBrowser.NavigateTo(Manager.Settings.BaseUrl); 
          Manager.ActiveBrowser.WaitUntilReady(); 
        } 

So instead of creating the objects for every test, I thought it would be possible to create at the class level. Does not seem to be working for me...

Ta 




0
Missing User
answered on 29 Jun 2010, 11:18 PM
Hi again SD,

Based on your Navigate class, are you sure you need to create objects every time you need to use the methods?

I remember the 'new' Manager code, but since it doesn't seem like you are extending any functionality for BaseTest, it looks like you can at least have Navigate as a static class and method that just accepts the main Manager as an argument.

If you were creating separate tests using the VSUnit Template that would need explicit setup/teardown and use them interchangeably in other VSUnit Template tests, then you would need to create separate test object instances.

Kind regards,
Nelson
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
SD
Top achievements
Rank 1
Answers by
Missing User
SD
Top achievements
Rank 1
Share this question
or