简体   繁体   中英

How to write Jemmy unit tests?

I'm searching for a good tool for writing regression tests for our Java Swing GUI. I found jemmy2 and I'm really satisfied with it.

There is one little drawback though: As the jemmy examples show, I have to write each test class as an org.netbeans.jemmy.Scenario : the test code goes to the public int runIt() method. I prefer to have more conventional unit tests with the usual given-when-then structure and with meaningful assertions. I'd really like to integrate jemmy with a unit testing framework like junit or testng.

So, the question: how can I do that? I know that it's possible because the JellyTools did it - in a NetBeans-specific way.

Alternatively, how can I get meaningful error reports from my jemmy scenarios?

Jemmy could be used with any test harness like JUnit, TestNG, what have you.

You do not need to do anything special - just use Jemmy API directly from test methods. With JUnit and TestNG you also get nice @Before to run the tested app.

Shura

Meanwhile I learned that it's fairly easy:

@Test
public void testSomething() throws Exception {
            //GIVEN
        ClassReference cr = new ClassReference("components.TableFilterDemo");
    cr.startApplication();
    frame = new JFrameOperator("TableFilterDemo");

            //WHEN
            //doing more steps

            //THEN
            //do TestNG assertions
}

The big difference is that this way the test can throw Jemmy-related exceptions. But then, they are meaningful test messages, so it's OK.

As for "meaningful error reports" ....

A decent test harness will create a report saying which tests failed.

If you want to know more of what went wrong, you could get it from the excessive Jemmy log. You will have to provide your own logging to get some meaningful trace on the application level.

Shura

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