Assert function for Dialogue box
In my application there are 3 textboxes and a button. If a user doesnot fill any of these textboxes and hits the button, a message box is shown to user saying a particular textbox is not entered.
Now how can I use Ass开发者_开发技巧ert to confirm that message box was popped or not?
Thanks for your answers in advance.
For this kinds of GUI Unit testing, the cleaner solution is to abstract UI side effects behind an interface.
So instead of calling something like :
ShowErrorMessage("This is bad");
You create an interface responsible for showing the object
public interface MessageShower {
public function showMessage(String msg);
}
In real life, your code will use a concrete implementation :
public class ConcreteMessageShower {
public function showMessage(String msg) {
ShowErrorMessage(msg);
}
}
However in unit test you will use a fake implementation, or a stub, or a mock.
This is really the general question of "how do I test UI side effect ?", to which the answer is : "you don't !" ;)
Hoping this helps.
精彩评论