简体   繁体   中英

Test event handler on TextButton

I am trying to write unit test the custom handler added to the TextButton via addSelectHandler .

I am adding the event handler as

public class TestClass {
    public void add(TextButton button) {
        button.addSelectHandler(new SelectHandler() {
            @Override
            public void onSelect(SelectEvent selectEvent) {
                System.out.println("This is called");
            }
        });
    }
}

Now in the test, I am trying to do the following

@Test
    public void test() {
        TextButton textButton = new TextButton();
        TestClass testClass = new TestClass(); 
        testClass.add(textButton);
        textButton.fireEvent(new SelectEvent());
    }

However, the log is never printed. I am not sure what is wrong here. Can somebody help me here?

You possibly need to set delayTestFinish(500);

This makes your GWT test case asynchronous.

See "Asynchronous Testing" on http://www.gwtproject.org/doc/latest/DevGuideTesting.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM