Hi Guys,
Apologies for asking the same question again but I think I was not clear enough in the previous time:
Using the WebAii Nunit template, I've got 2 separate CS. files. One file contains tests that call helper methods from the other.
The file that contains the tests:
namespace MyTests
{
[TestFixture]
public class TestCase_Login : BaseTest
{
Paths Path = new Paths ();
[Test]
public void LoginBase()
{
Path.baseLogin();
}
}
}
The other file that contains the helper methods:
namespace Helpers
{
class Paths : BaseTest
{
public void baseLogin()
{
Manager.LaunchNewBrowser(BrowserType.FireFox);
Manager.SetNewBrowserTracking(true);
ActiveBrowser.NavigateTo(Manager.Settings.BaseUrl);
Manager.ActiveBrowser.WaitUntilReady();
}
}
}
Trying to run the test will result:
System.NullReferenceException: Object reference not set to an instance of an object.
I understand that there is no testsetup run for the Paths class so the inherited BaseTest Manager objectis not instantiated and is not settable to the outer class' Manager referencesince the BaseTest Manager reference is read only.
As I want to keep the helper methods in a separate cs. file, could please advice how should I create a private manager property for
the Paths class (And similar classes) and how to pass the outer class manager in the constructor in order to be able to use a single instantiated Manager object to be used in the different helper classes.
Thanks in advance,
SD.
7 Answers, 1 is accepted
0
Hello SD,
Thanks for clearing this up, it reminds me of another customer who had something similar. Please check out this thread and my post on it to see if this applies.
The classes call and initialize each other internally, but you can probably do the same in your calling test script.
Please let us know if that is what you had in mind.
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.
Thanks for clearing this up, it reminds me of another customer who had something similar. Please check out this thread and my post on it to see if this applies.
The classes call and initialize each other internally, but you can probably do the same in your calling test script.
Please let us know if that is what you had in mind.
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.
0

SD
Top achievements
Rank 1
answered on 13 May 2010, 01:13 AM
Hi Nelson,
Sorry, I could not make it work. I'm probably doing something wrong here...
- The TestCase class is webaii Nunit template.
- The Helper class is just a class I added to the Solution using Add-> New Item->Class
- Both TestCase & Helper live under the same namespace in separate files.
I'm not quite clear to where to position the initialization statement (Appears as myA.Initialize(B.Manager); in the last thread)
and the statement for creating a private manager (private new Manager Manager = null;)
Could you please indicated where should I place the required statements in the example below to allow calling Helper method/s from TestCase ?
Could you please indicated where should I place the required statements in the example below to allow calling Helper method/s from TestCase ?
namespace MYTESTS
{
[TestFixture]
public class TestCase : BaseTest
{
[Test]
public void StartFF()
{
Helper myHelper = new Helper(); //Should myHelper be initialized here ?
myHelper.launchFF();
}
}
}
//----------------------------------------
namespace MYTESTS
{
public class Helper : BaseTest
{
private new Manager Manager = null; //Where should Manager = TestCase.Manger placed ?
public void launchFF ()
{
Manager.LaunchNewBrowser(BrowserType.FireFox);
}
}
}
Ta in advance,
SD.
0

Chris Johnson
Top achievements
Rank 1
answered on 13 May 2010, 06:04 PM
SD -
I wouldn't derive helper classes from TestBase. If they are really just helpers, and not runnable tests in their own right, then I'd just pass any test domain objects you need to a helper constructor or directly to the methods that need them.
I'm using WebAii, not unit tests, but had a similar need: how to implement reusable helper methods I could call from code-behind test steps. I put the helper methods in a static helper class, and the calling test class passes a reference to self. The helper can pull out whatever its needs. (Well it wasn't quite that simple: I also had to pass the Pages reference, since it is defined in each concrete test class, not in BaseWebAiiTest.)
Actually I went a step further than this, and created a WebAiiTestContext class that the coded step populates with references to the important objects. The helper methods just take a reference to that context. It's a narrower interface than passing a reference to the entire BaseWebAiiTest. It may help keep things clean as my requirements grow, but I suppose that is debatable.
I wouldn't derive helper classes from TestBase. If they are really just helpers, and not runnable tests in their own right, then I'd just pass any test domain objects you need to a helper constructor or directly to the methods that need them.
I'm using WebAii, not unit tests, but had a similar need: how to implement reusable helper methods I could call from code-behind test steps. I put the helper methods in a static helper class, and the calling test class passes a reference to self. The helper can pull out whatever its needs. (Well it wasn't quite that simple: I also had to pass the Pages reference, since it is defined in each concrete test class, not in BaseWebAiiTest.)
[CodedStep(@"Test step that uses a helper method")] |
public void TestStepThatUsesHelperMethod() |
{ |
HelperMethods.HelpMe(this, Pages); |
} |
Actually I went a step further than this, and created a WebAiiTestContext class that the coded step populates with references to the important objects. The helper methods just take a reference to that context. It's a narrower interface than passing a reference to the entire BaseWebAiiTest. It may help keep things clean as my requirements grow, but I suppose that is debatable.
0
Hello all,
As Chris mentioned, you would need to pass in the objects initialized by the main test. So in your case SD, you would need to pass in Manager because, even though you inherited from BaseTest, it's Manager Property is not initialized.
The old AOT thread I sent in my last post refers to setting a Manager variable that will hide the base class's Manager Property so you can use similar variable/property in your inherited class like the following:
Thanks for the post Chris. Please reply back if there any questions on the above.
Best wishes,
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.
As Chris mentioned, you would need to pass in the objects initialized by the main test. So in your case SD, you would need to pass in Manager because, even though you inherited from BaseTest, it's Manager Property is not initialized.
The old AOT thread I sent in my last post refers to setting a Manager variable that will hide the base class's Manager Property so you can use similar variable/property in your inherited class like the following:
public
class
Helper : BaseTest
{
private
Manager _manager =
null
;
private
new
Manager Manager
{
set
{
_manager = value;
}
get
{
return
_manager;
}
}
public
Helper(Manager m)
{
Manager = m;
}
public
void
launchFF ()
{
Manager.LaunchNewBrowser(BrowserType.FireFox);
}
}
}
Thanks for the post Chris. Please reply back if there any questions on the above.
Best wishes,
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.
0

Chris Johnson
Top achievements
Rank 1
answered on 13 May 2010, 11:51 PM
I may be missing something here, but why are you both (SD and Nelson) deriving the helper class from BaseTest? Unless the helpers are tests themselves (which in the sample code I've seen so far, they are not), then what is the rationale for doing that? You are inheriting state and behavior that is not applicable and is getting in your way. Why not simply have a stand-alone helper class that does not inherit from BaseTest (or in my case, BaseWebAiiTest).
0
Hi Chris,
Thanks for pointing this out, there really would not be a need to inherit from BaseTest if the class is strictly a helper class. So the code I posted would not need to have the inheritance, and could even be declared static along with it's members as you mentioned.
So as long as the Manager instance is passed in, that would be all you need to do most of the testing in the framework you would require. I believe you could also pass in 'this' also in a framework test as you are in the WebUI test, just to get a bit more functionality from the initialized main test's BaseTest.
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.
Thanks for pointing this out, there really would not be a need to inherit from BaseTest if the class is strictly a helper class. So the code I posted would not need to have the inheritance, and could even be declared static along with it's members as you mentioned.
So as long as the Manager instance is passed in, that would be all you need to do most of the testing in the framework you would require. I believe you could also pass in 'this' also in a framework test as you are in the WebUI test, just to get a bit more functionality from the initialized main test's BaseTest.
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.
0

SD
Top achievements
Rank 1
answered on 14 May 2010, 05:12 AM
TA Nelson, working now.
My TestCase looks like that now so I'm calling and exc. lanunchFF() from the test.
public class TestCase : BaseTest |
{ |
[Test] |
public void StartFF() |
{ |
Helper myHelper = new Helper(Manager); |
myHelper.launchFF(); |
} |
} |
} |
I guess using the term 'Helper/s' in my previous posts was a bad call as methods like lanunchFF() are not exactly Helpers but a chuck
of exc. called from elsewhere. That's the way I'm usually constructing my tests, having a bunch of classes with various methods and a single or multiple TestCase that utilize those methods in the same fashion launchFF() is used under the StartFF test.
That way, I'm creating a set of dedicated 'Test API's' to make the writing of tests easier & faster.
Thanks for you comments Chris, I'll be more then happy any suggestions regarding test arch. etc.
Ta,
SD.