locked
testing GUI - unit test RRS feed

  • Question

  • hello

    I have problem. I have hundreds of methods which have only one line which makes them impossible to test (so far). I mean MessageBox.Show("haha, your unit test shall fail, young tester!"); Its code i cannot change, developer team wont make my life easier :)

    as we all know, to close that kind of window, we have to manually click some button. Is there any possible way to deal with that kind of messages? I tried to register my stub window and set visibility to hidden, but then, vs2010 professional inform me that i cannot use that window if it hasn't been activated before.

    thanks for any tips !

    Tuesday, August 2, 2011 6:54 AM

Answers

  • Hi,

    I am afraid there is not, They should use the "C# Preprocessor Directives" so if the developer need to write code for debugging, he/she should inside if debug directive

     

    Like this

    #define DEBUG
    // ...
    #if DEBUG
      MessageBox.Show("Debug version");
    #endif
    

     

    So if your run your test on Release or custom configuration it will not appear

    Updated

    A good link

    Leverage the C# Preprocessor

    Thanks

    M.Radwan


    We are volunteers, if the reply help you mark it as your answer. thanks!!

    Blog: http://mohamedradwan.wordpress.com

     M.Radwan

    Tuesday, August 2, 2011 3:37 PM

All replies

  • Hi,

    I am afraid there is not, They should use the "C# Preprocessor Directives" so if the developer need to write code for debugging, he/she should inside if debug directive

     

    Like this

    #define DEBUG
    // ...
    #if DEBUG
      MessageBox.Show("Debug version");
    #endif
    

     

    So if your run your test on Release or custom configuration it will not appear

    Updated

    A good link

    Leverage the C# Preprocessor

    Thanks

    M.Radwan


    We are volunteers, if the reply help you mark it as your answer. thanks!!

    Blog: http://mohamedradwan.wordpress.com

     M.Radwan

    Tuesday, August 2, 2011 3:37 PM
  • How about using coded ui for windows forms, please refer http://msdn.microsoft.com/en-us/library/dd286681.aspx

    Thanks,

    Anuj


    http://www.anujchaudhary.com/
    Wednesday, August 3, 2011 5:08 AM
  • I use VS2010 Professional. First sentence from this article "Using Visual Studio Premium or Visual Studio Ultimate, you can create a coded UI test that can test that the user interface for an application functions correctly".
    Wednesday, August 3, 2011 7:16 AM