tags:

views:

28

answers:

2

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 Assert to confirm that message box was popped or not?

Thanks for your answers in advance.

A: 

I used Assert.IsNotNUll(object); and its working.. Thanks shane.

shanthiram
A: 

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.

phtrivier