Java Swing GUI 的自动化测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/91179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automated tests for Java Swing GUIs
提问by pauldoo
What options are there for building automated tests for GUIs written in Java Swing?
有哪些选项可以为用 Java Swing 编写的 GUI 构建自动化测试?
I'd like to test some GUIs which have been written using the NetBeans Swing GUI Builder, so something that works without requiring special tampering of the code under test would be ideal.
我想测试一些使用NetBeans Swing GUI Builder编写的GUI,因此不需要对被测代码进行特殊篡改即可工作的东西将是理想的选择。
采纳答案by Jwest08
Recently I came across FEST which seemed promising, except that the developer announced in 2012 that development would not continue.
最近我遇到了 FEST,它看起来很有希望,只是开发商在 2012 年宣布不会继续开发。
AssertJis a fork of FEST that is working very well for me. It is actively maintained (at time of writing), supports Java 8, has assertions for a few popular libraries such as Guava and Joda Time, and is very well documented. It is also free and open.
AssertJ是 FEST 的一个分支,对我来说效果很好。它得到积极维护(在撰写本文时),支持 Java 8,对一些流行的库(如 Guava 和 Joda Time)有断言,并且有很好的文档记录。它也是免费和开放的。
回答by pauldoo
I haven't used it personally, but SwingUnitlooks quite good. You can use it with jUnit, and it isn't based on "location of components" (i.e. x and y co-ordinates).
我个人没有使用过它,但SwingUnit看起来相当不错。您可以将它与 jUnit 一起使用,它不基于“组件位置”(即 x 和 y 坐标)。
The only thing you may have to do with the NetBeans GUI Builder is set unique names for your components.
您可能需要使用 NetBeans GUI Builder 做的唯一一件事就是为您的组件设置唯一的名称。
回答by deterb
I'm currently using FEST. It works with JUnit and will also take screenshots of failed tests.
我目前正在使用FEST。它与 JUnit 一起使用,并且还会截取失败测试的屏幕截图。
It has default component hunting methods which look for the name of the component being tested (which need to be set manually), but you can also generate the testers for a given component by passing it the component.
它具有默认的组件搜索方法,用于查找被测试组件的名称(需要手动设置),但您也可以通过将组件传递给给定组件来为给定组件生成测试器。
回答by Javaxpert
I use java.awt.Robot
. Is not nice, is not easy but works every time.
我用java.awt.Robot
. 不好,不容易,但每次都有效。
Pros:
优点:
- You are in control
- Very fast
- Build your own FWK
- Portable
- No external dependencies
- 你尽在掌握
- 非常快
- 建立自己的 FWK
- 便携的
- 没有外部依赖
Cons:
缺点:
- No nice GUI to build test
- You have to leave the GUI alone while you test
- Build your own FWK
- Difficult to change test code and create your first harness
- 没有漂亮的 GUI 来构建测试
- 您在测试时必须单独离开 GUI
- 建立自己的 FWK
- 难以更改测试代码并创建您的第一个工具
Now if you have the budget I would go for LoadRunner. Best in class.
现在,如果您有预算,我会选择 LoadRunner。全班最优。
(Disclosure: relationship to the company that owns LR, but I worked with LR before the relationship)
(披露:与拥有LR的公司的关系,但我在关系之前与LR合作)
回答by Dema
You can try to use Cucumberand Swingerfor writing functional acceptance tests in plain english for Swing GUI applications. Swinger uses Netbeans' Jemmy library under the hood to drive the app.
您可以尝试使用Cucumber和Swinger为 Swing GUI 应用程序编写纯英语的功能验收测试。Swinger 在幕后使用 Netbeans 的 Jemmy 库来驱动应用程序。
Cucumber allows you to write tests like this:
Cucumber 允许您编写这样的测试:
Scenario: Dialog manipulation
Given the frame "SwingSet" is visible
And the frame "SwingSet" is the container
When I click the menu "File/About"
Then I should see the dialog "About Swing!"
Given the dialog "About Swing!" is the container
When I click the button "OK"
Then I should not see the dialog "About Swing!"
Take a look at this Swinger video demoto see it in action.
看看这个Swinger 视频演示,看看它的实际效果。
回答by Jayan
回答by Viktor Mellgren
Sikuli: a GUI-tester using screenshots http://sikuli.org/
Sikuli:使用屏幕截图的 GUI 测试器 http://sikuli.org/
回答by Hashan
You can use Marathon: "Marathon Integrated Testing Environment, MarathonITE, is an affordable, easy-to-use and cross-platform Java/Swing? GUI Test automation framework. You can use MarathonITE‘s inbuilt script recorder to create clean, readable test scripts either in Python or Ruby. Advanced features like extract-method refactoring, create-datadriven-tests and objectmap editing allows you to create maintainable, resilient test suites."
您可以使用Marathon:“Marathon 集成测试环境 MarathonITE 是一种经济实惠、易于使用且跨平台的 Java/Swing?GUI 测试自动化框架。您可以使用 MarathonITE 的内置脚本记录器来创建干净、可读的测试脚本在 Python 或 Ruby 中。提取方法重构、创建数据驱动测试和对象映射编辑等高级功能允许您创建可维护、有弹性的测试套件。”