简体   繁体   English

Javax Swing GUI应用程序的单元测试问题-合适的JDK 7选项?

[英]Unit testing issues with Javax Swing GUI application - suitable JDK 7 option?

I require to test an application which uses a Swing GUI interface. 我需要测试使用Swing GUI界面的应用程序。 I have a client/server design and want to simulate client input (from the client's interface) and retrieve the server response. 我有一个客户端/服务器设计,想要模拟客户端输入(从客户端的界面)并检索服务器响应。

So far I have looked into jfcUnit and UISpec4J for JDK 7, with use under NetBeans. 到目前为止,我已经研究了在NetBeans下使用的JDK 7的jfcUnit和UISpec4J。 Attempting to find a named component from the window instance returned nothing using jfcUnit (using the NamedComponentFinder), example comes from here under the login screen example. 尝试使用jfcUnit(使用NamedComponentFinder)从窗口实例中查找命名组件没有返回任何结果 ,该示例来自登录屏幕示例下的此处 I assume the name is its string variable name in the class. 我假设名称是其在类中的字符串变量名称。

The test method I used for searching a client 'Connect' button which gave the empty list result is as follows, where gui is the client gui class(following the rest of the login example above): 我用于搜索给出空列表结果的客户端“连接”按钮的测试方法如下,其中gui是客户端gui类(在上述登录示例的其余部分之后):

 @Test
    public void testConnectVisible () {
        NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "connectBtn" );
        List allItems = finder.findAll(gui);
        System.out.println(allItems.toString());
    }

Another was UISpec4J, although I can't find a .jar compatible with JDK 7. Its documentation is fuller and would be more suitable. 另一个是UISpec4J,尽管我找不到与JDK 7兼容的.jar。它的文档更完整,更适合。

Does anyone know of a suitable GUI testing framework under JDK 7, or a working example of either of UISpec4J/jfcUnit for JDK 7? 有谁知道JDK 7下合适的GUI测试框架,或者JDK 7的UISpec4J / jfcUnit的工作示例? I need some way of emulating event-based triggering on the client side. 我需要某种方式在客户端上模拟基于事件的触发。

Edit I would also like to simulate multiple clients, which would require a testing framework that supports several client windows in one test instance. 编辑我还想模拟多个客户端,这需要一个在一个测试实例中支持多个客户端窗口的测试框架。

Many thanks :) 非常感谢 :)

In general it is best to not to need to test much in the GUI. 通常,最好不要在GUI中进行太多测试。 Your GUI code should have no business logic in it at all. 您的GUI代码中应该根本没有业务逻辑。 All of your GUI code should just call code in your business layer. 您的所有GUI代码都应该只在业务层中调用代码。

The code in the business layer is easily testable using normal unit tests. 使用正常的单元测试,可以轻松测试业务层中的代码。 Which will make your GUI tests as few in number as possible. 这将使您的GUI测试数量尽可能少。

Having said all of that, many years ago I used a framework called abbot which sounds just like what you need. 综上所述,很多年前,我使用了一个名为abbot的框架,听起来像您所需要的。 I just checked their website and it says it should work with Java 7 and tested against java 6. 我刚刚检查了他们的网站,并说它应该与Java 7一起使用,并针对Java 6进行了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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