Unit Testing forms and Events in c# -


i want write test cases c# code triggers events or displays form user input e.g.:

private void createrecord_click(object sender, eventargs e) {     try     {         this.initiaterecording();     }     catch (bubbleuiexception ex)     {         objlog.error(textres.idc_eshuttleerror, ex);         messagebox.show(             ex.message,             textres.idc_eshuttleerror,             messageboxbuttons.ok,             messageboxicon.error);      }      catch (exception ex)      {          objlog.error("error occurred", ex);          messagebox.show(              ex.message,              textres.idc_error,              messageboxbuttons.ok,              messageboxicon.error);      }  } 

how write unit tests these kind of code using mbunit?

test:

  1. this.initiaterecording() called
  2. force bubbleuiexception when this.initiaterecording() called
  3. force exception not bubbleuiexception when this.initiaterecording() called
  4. wrap messagebox.show can test prints expect when exceptions thrown.
  5. test objlog.error called.

you can assume click event works (that method called when control clicked) microsoft have tested this.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -