NullReferenceException at TestCase.Status

Bug reports.
Dirk
Posts: 2
Joined: Tue Dec 09, 2014 12:25 pm

NullReferenceException at TestCase.Status

Post by Dirk » Wed Feb 24, 2016 11:37 am

Hello Support Team,

I am receiving a NullReferenceException while retrieving the status of all activated test cases. At the end of my test run I want to list all my activated test cases that have failed. So at the teardown step I retrieve a list of the cases with

Code: Select all

TestSuite.Current.SelectedRunConfig.GetActiveTestCases()
Then I enumerate through the list and look for test cases that have a failed status. But when I access the Status property I receive a NullReferenceException. The stacktrace is the following:

Code: Select all

Ranorex.Core.Testing.TestCase.get_Status() at PDVWipDotNet._TOOLS.CheckTestResult.Check() at c:\Ranorex\PDVWipDotNet\PDVWipDotNet\_TOOLS\CheckTestResult.UserCode.cs:Row 46. at PDVWipDotNet._TOOLS.CheckTestResult.Ranorex.Core.Testing.ITestModule.Run() in c:\Ranorex\PDVWipDotNet\PDVWipDotNet\_TOOLS\CheckTestResult.cs:Row 82. at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext)
My Ranorex version is 5.4.5.19886


Best regards

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: NullReferenceException at TestCase.Status

Post by odklizec » Thu Feb 25, 2016 9:39 am

Hi,

Could you please post the entire code (list enumeration) where Ranorex fails? Also, I would suggest to move the code from teardown section to program.cs (at the end of program.cs, just before return error; line).
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Dirk
Posts: 2
Joined: Tue Dec 09, 2014 12:25 pm

Re: NullReferenceException at TestCase.Status

Post by Dirk » Thu Feb 25, 2016 12:17 pm

The source code is the following:

Code: Select all

IList<TestCase> cases = TestSuite.Current.SelectedRunConfig.GetActiveTestCases();
if(cases != null){
    int failed = 0;
    for(int i = 0; i < cases.Count; ++i){
        if(cases[i] != null){
        	if(cases[i].Status == ActivityStatus.Failed){
        		++failed;
        	}
        }
    }
}
I have encapsulated this source code into an record module with user code to be able to just plug it into several run configurations with different test cases. If I would move it to the end of Program.cs it would be executed at every run configuration. But i can try it for testing purpose.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: NullReferenceException at TestCase.Status

Post by Support Team » Mon Feb 29, 2016 4:52 pm

Hi Dirk,

This error usually occurs when executing the module itself and not the whole test suite.
I tried your code and it worked when executing the test suite.
Please let me know if it doesn't work when executing the test suite as well.

Regards,
Bernhard
.
Image