masterdany88
masterdany88

Reputation: 5341

Can I and Should I test fireEvent and Handlers method in GWT?

I am writting test for GWT, but I did not find any example of fireEvent test. Can any one help me?

I have event that has handler which put some current variable on the list. I would like to test the method that fires an event?

Does this make any sense to anyone?

Do we need such Unit tests?

Upvotes: 0

Views: 464

Answers (1)

Ümit
Ümit

Reputation: 17489

I would split up the tests

  1. Test if the event is fired
  2. Test the method that puts a variable on a list by just calling the method directly

Regarding 1: You can use com.google.gwt.event.shared.testing.CountingEventBus and then use getCount(GwtEvent.Type) to check how many times the event was fired, see here for more infos.
If you pass data in your event object and you want to test that you can create your own fake EventBus (see this and this test for more infos)

You can also test that the your handler is properly executed when you fire the event. Just fire the event on the EventBus and use an assertion for the list (see this test for an example)

Upvotes: 1

Related Questions