Put this code into a child test:
public override void OnAfterTestCompleted(TestResult result)
{
base.OnAfterTestCompleted(result);
string parentName = Convert.ToString(result.Parent.Name);
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
}
Now run the parent test that calls this child test.
Expected: The test to pass
Actual:
>>> Test-as-Step 'TestResultParentIssue\Child.tstest' log starts:
------------------------------------------------------------
'4/4/2014 3:24:55 PM' - Detected custom code in test. Locating test assembly: Telerik Troubleshooting.dll.
'4/4/2014 3:24:55 PM' - Assembly Found: F:\Dropbox\Support Issues\Telerik Troubleshooting\Telerik Troubleshooting\bin\Telerik Troubleshooting.dll
'4/4/2014 3:24:55 PM' - Loading code class: 'Telerik_Troubleshooting.Child'.
------------------------------------------------------------
'4/4/2014 3:24:56 PM' - Error attempting to execute a Test As Step. Details:
'4/4/2014 3:24:56 PM' - System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik_Troubleshooting.Child.OnAfterTestCompleted(TestResult result) in f:\Dropbox\Support Issues\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)
<<< Test-as-Step 'TestResultParentIssue\Child.tstest' log ends.
Upon closer inspection you will find that TestResult.Parent is null.