Mixing Assert and Act in AAA unit testing syntax -


is ok mix assert , act steps? aaa more of guideline rule? or missing something?

here test:

[testmethod] public void cancelbuttonselected_dontcanceltwicethencancel_dialogcloses() {     // arrange     iaddaddressform form = substitute.for<iaddaddressform>();     // indicate when show cancelmessage called      //  should return cancel twice (saying want cancel cancel)     //  should return ok     form.showcancelmessage().returns(dialogresult.cancel,           dialogresult.cancel, dialogresult.ok);      addaddresscontroller controller = new addaddresscontroller(form);     addressitem item = testhelper.createaddressbob();      // act     enteraddressinfo(form, controller, item);     controller.cancelbuttonselected();     assert.istrue(form.dialogresult == dialogresult.none);      controller.cancelbuttonselected();     assert.istrue(form.dialogresult == dialogresult.none);      controller.cancelbuttonselected();      // assert     assert.istrue(form.dialogresult == dialogresult.cancel); } 

so call method 3 times. after each call, want make sure did not cancel dialog. on third call, dialog should canceled.

is "legal" use of aaa syntax/styling?

aaa guideline make unit tests more readable. in example provided argue have not achieved goal.

i think following tests make scenario testing more readable.

[testmethod] public void cancelbuttonselected_shouldsetdialogresulttonone_whenfirstcancelbuttonisselected() {     // arrange     iaddaddressform form = arrangeformforcancelbuttonselectedtests();     addaddresscontroller controller = arrangecontrollerforcancelbuttonselectedtests();      // act     controller.cancelbuttonselected();      // assert     assert.istrue(form.dialogresult == dialogresult.none); }  [testmethod] public void cancelbuttonselected_shouldsetdialogresulttonone_whensecondcancelbuttonisselected() {     // arrange     iaddaddressform form = arrangeformforcancelbuttonselectedtests();     addaddresscontroller controller = arrangecontrollerforcancelbuttonselectedtests();      // act     controller.cancelbuttonselected();     controller.cancelbuttonselected();      // assert     assert.istrue(form.dialogresult == dialogresult.none);  }  [testmethod] public void cancelbuttonselected_shouldsetdialogresulttocancel_whenthirdcancelbuttonisselected() {     // arrange     iaddaddressform form = arrangeformforcancelbuttonselectedtests();     addaddresscontroller controller = arrangecontrollerforcancelbuttonselectedtests();      // act     controller.cancelbuttonselected();     controller.cancelbuttonselected();     controller.cancelbuttonselected();      // assert     assert.istrue(form.dialogresult == dialogresult.cancel); } 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -