Forum Discussion

Anastasia's avatar
Anastasia
New Contributor
8 years ago

Sometimes tests fail in a random way

Hello!

 

I have problems with running my tests. Some tests fail in a random way. Tests, have been failed once, can be passed next time.

 

Error examples:

 

System.InvalidCastException : Unable to cast object of type 'System.DBNull' to type 'System.String'.
at AutomatedQA.script.var.op_Implicit(var arg)


System.MissingMethodException : Method 'System.DBNull.Click' not found.
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at AutomatedQA.script.var.VarDelegate.CallNoPop(var[] args)
at AutomatedQA.script.var.VarDelegate.CallStatic(var[] args)


System.InvalidCastException : Specified cast is not valid.

 

Can you help me? How can I solve this problem?

 

OS: Windows 7

TestComplete/Test Execute version: 10.0.531.7

 

Thank you!

 

Anastasia

7 Replies

  • What is your test attempting to do when this error occurs? Can you post your script code where the error is happening?

     

    Without more info it's hard to say, but it looks like you are probably pulling data from a database and your script expects that data to be a string, but sometimes it is Null. If the values you are pulling from the database for that column can be Null then you need to have your code handle null values properly.

    • Anastasia's avatar
      Anastasia
      New Contributor

      Thank you for repply!

       

      I'll try to describe a problem in more detail.

      There are about 150 test cases in our project. I write them to test a .NET WinForms application. Tests perform operations with DevExpress controls, I don't work with database there. Test cases are also written in .NET (C#).

      If I run tests on my computer (Windows 7) using Visual Studio, this problem doesn't appear, and all tests are successfully passed. But when I run these tests on remote computer using NUnit, some tests fail randomly.

       

      Examples of errors:

       

       

      1.
      System.InvalidCastException : Unable to cast object of type 'System.DBNull' to type 'System.String'.
      at AutomatedQA.script.var.op_Implicit(var arg)
      at iikoTest.Office.Controls.OfficeContextMenu.Select(String itemtext) in c:\OfficeAutotest\Tests\OfficeTests\iikoTest.Framework.Office.Controls\src\OfficeContextMenu.cs:line 125
      
      2.
      System.MissingMethodException : Method 'System.DBNull.Click' not found.
      at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
      at AutomatedQA.script.var.VarDelegate.CallNoPop(var[] args)
      at AutomatedQA.script.var.VarDelegate.CallStatic(var[] args)
      at iikoTest.Office.Controls.OfficeButton.<Click>b__0() in c:\OfficeAutotest\Tests\OfficeTests\iikoTest.Framework.Office.Controls\src\OfficeButton.cs:line 32
      
      3.
      System.InvalidCastException : Specified cast is not valid.
      at iikoTest.Office.Controls.OfficeRadioGroup.FindItemByText(String itemtext) in c:\OfficeAutotest\Tests\OfficeTests\iikoTest.Framework.Office.Controls\src\OfficeRadioGroup.cs:line 65

       

      I can send you report made by ReportGenerator.exe.

       

      Thank you!

      • ghuff2's avatar
        ghuff2
        Contributor

        Sorry, I don't really have any experience in that area. Might want to contact smartbear support if no one else on here is able to help.

  • Anastasia's avatar
    Anastasia
    New Contributor

    , yes, it is.

    I want to add one remark. I run tests in Visual Studio, while I'm debugging them. Then I put .dll on remote computer and run them using NUnit console. Problem is reproduced in this case.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Gotcha... 

      So, is it possible for you to post the actual code that is generating the error messages in your DLL?  The reason being is that somewhere in your code, something is being read in as a DBNull value and you are attempting to cast that as some other value (string, integer, something).  

      If you can't post the code for privacy reasons, the next best suggestion is to take a look through your code and make sure you do any necessary checks for a "NULL" value... like if you are trying to grab information from internally in your AUT and use it in your test code.  Your test code may not be using a database but your application under test may be and, if that's the case, it could be returning a NULL value that your test isn't designed to handle.

      This is all conjecture and best guess but that's where I would start looking, based upon the error message you are seeing.