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.