Skip to main content

testing databindings and actions

4 replies [Last post]
jtr
Offline
Joined: 2003-06-10

It seems to me that one of the testing benefits of JDNC is that the UI is separated from the program logic which should lead to easily testable program logic via unit tests.

I haven't dived in here myself yet. Has anyone explored this area? Any suggestions?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rbair
Offline
Joined: 2003-07-08

It seems like an obvious idea -- I wonder why I didn't think of it :).

If I understand you correctly you're talking about affixing application level unit testing to the binding framework (or some such endpoint), rather than tests the JDNC team would write, correct?

I'm not sure exactly how the unit tests would be constructed because one piece of code would programatically fire an event (like somebody clicking the "ok" button), and another piece of code would have to check that the proper stuff happened. I'm sure somebody out there has worked on this. I'd hit google if I were you (I seem to remember an article some time ago...perhaps on O'Reilly).

Richard

Mark Davidson
Offline
Joined: 2006-02-17

There are quite a few unit tests for actions and data. Take a look at following directories or classes:

swingx/src/test/org/jdesktop/swing/actions
swingx/src/test/org/jdesktop/swing/binding
swingx/src/test/org/jdesktop/swing/data
jdnc_markup/src/test/org/jdesktop/jdnc/markup/ActionsTest.java
jdnc_api/src/test/org/jdesktop/jdnc/JNActionsTest.java

You can see enough in these packages and classes to get you started.

To run the tests, go to a "make" sub-directory and type:

$ ant test

There are a couple of properties that you can pass into the test target using the "-D" arg.

-Dtest.class=path.to.a.TestClass

will run a single JUnit test class

-Dtest.package=path/to/a/package

will run all the tests in a package. You must use "/" rather than "." since the package is represented as a sub-directory in the ant property

Good luck and have fun.

--Mark

jtr
Offline
Joined: 2003-06-10

Thanks Mark... I should have been more explicit. The actual mechanics of testing I did see in the sources. But I was wondering about how people thought of structuring their code vs with hand code GUIs - wrt testing.

For example, if I use the NetBeans Form builder, I usually end up with the equivalent of my actions, my gui, and my data mixed into one class. Not by design, but by convenience. But with JDNC, the gui is separated out by design. And now I have a choice of separating my actions from my javabeans. On the surface, that seems like a good idea, but if the javabean and the action are tightly related to each other, I have to wonder if they really do belong together (in this case, they'd have high coehsion).

And since I'm no unit testing guru, I'm probably missing a bunch of other issues.

jtr
Offline
Joined: 2003-06-10

I haven't formulated any opinions yet, but I did find a few articles about this area:

http://today.java.net/today/2003/10/16/ch13gui.pdf
http://www.xp123.com/xplor/xp0001/
http://www.xp123.com/xplor/xp0002/