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

Unable to access TestResult.Parent properties from OnAfterTestCompleted in a test-as-step

4 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 01 Apr 2014, 11:42 AM
My project has a shared test-as-step that each of my other tests call.  This test-as-step has the following override that is attempting to use properties of the testresult parent/calling test name to add to the custom log we've created:

public override void OnAfterTestCompleted(TestResult result)
{
base.OnAfterTestCompleted(result);

string parentName = Convert.ToString(result.Parent.Name); //line 103
string parentId = Convert.ToString(result.Parent.Id);
string parentRootName = Convert.ToString(result.Parent.RootName);
string fileName = Convert.ToString(result.Parent.FileName);

\\custom code to write to the log
}

Each line in the above override that references the testresult.parent.* properties test trigger the following error:
System.NullReferenceException: Object reference not set to an instance of an object.
   at CIS.TestStudio.WebAccess.Shared.Handler.OnAfterTestCompleted(TestResult result) in c:\tfs\CoreCM\Root\CIS.TestStudio.WebAccess\Shared\Handler.tstest.cs:line 103
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTestIteration(Object codeBehindInstance, Boolean isDataDriven)
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteDataDrivenTest(Test test, BaseWebAiiTest codeInstance)
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult)
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteTestInCurrentContext(Test test)

If this is not the correct way to access the name of the parent/calling test properties, is there a better way to do so through code?

4 Answers, 1 is accepted

Sort by
0
Nick
Top achievements
Rank 1
answered on 01 Apr 2014, 05:24 PM
I've attached a sample project showing the issue I'm experiencing.  If you quick execute the test named "Parent.tstest" in folder "TestResultParentIssue", you will see the following error:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik_Troubleshooting.Child.OnAfterTestCompleted(TestResult result) in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\TestResultParentIssue\Child.tstest.cs:line 78
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTestIteration(Object codeBehindInstance, Boolean isDataDriven)
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult)
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteTestInCurrentContext(Test test)
0
Cody
Telerik team
answered on 04 Apr 2014, 08:34 PM
Hello Nick,

Bug confirmed. I've granted you some Telerik Points for reporting this to us. Why do you need those parameters in the child test? An alternative would be to store that data into a global C# variable while in the parent test which the child test can access.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nick
Top achievements
Rank 1
answered on 06 Apr 2014, 07:43 PM
Thanks Cody.

I originally needed it because I added custom logging that first checks for a logfile at "<path>\<testname>.txt" and either adds to it or creates it if it doesn't exist, then populates the run results in the file.  The problem I was having was that when I have a shared test that other tests call (shared.tstest), it would write the results to both the <path>\shared.txt file and the <path>\parenttest.txt log file.  I figured out a workaround, which was to just add a check to my execution extension dll that the test name was not "shared" prior to logging any events.  Now when a failure occurs in a shared test, the result propagates to the parent test so the results are still captured.
0
Cody
Telerik team
answered on 07 Apr 2014, 12:41 PM
Hello Nick,

That sounds like a very good alternative. Thank you for the update.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Nick
Top achievements
Rank 1
Cody
Telerik team
Share this question
or