GIMP 现在有 UI 测试
GIMP now has UI tests

原始链接: https://www.gimp.org/news/2026/11/16/gimp-ui-tests/

GIMP 现在拥有自动化 GUI 测试,它们会启动真实应用程序,与菜单、按钮、对话框和工具进行交互,并验证结果。这些测试是对单元测试的补充——单元测试不会打开真实窗口——能够更早地捕获界面层面的缺陷。当前的 13 项测试涵盖了启动、欢迎对话框、新建图像、PNG 导出、颜色交换/输入、图层、撤销/重做、缩放、工具选择和填充桶、偏好设置保存以及图像扁平化。测试在没有显示器的情况下通过隐藏桌面运行,适合 CI 环境;并通过无障碍信息定位控件,同时也改善了屏幕阅读器的支持。它们使用 dogtail,其中包含一项向上游贡献的新特性;目前仅支持 Linux。项目邀请贡献者为更多功能添加测试。

GIMP 宣布它现在有 13 个启动真实实例的 UI 测试,不同于其早期的单元测试和旧版 GUI 测试。Hacker News 评论者就 GIMP 对贡献者的限制性 AI 政策展开辩论,一些人认为 AI 可以快速生成测试,另一些人则出于质量、伦理或环境原因捍卫仅由人类开发。该帖还讨论了测试质量、常被批评的 GIMP UI,以及 Photocraft/ArtCraft 和 Linux 上的 Affinity 等替代品。一些用户表示 GIMP 仍然有用且有悠久历史,而另一些人预测支持 AI 的工具可能会超越无 AI 政策的项目。其他旁支辩论包括 AI 检测的可靠性、AI 编写的测试是否真正有用,以及 GIMP 在更广泛的 Linux 桌面生态系统中的作用。
相关文章

原文

GIMP has a lot of intertwined menus, dialogs and tools. When we change a part of the interface, another may stop working and sometimes, the problem can be missed until a user reports it.

To find these problems early, a new GUI testing platform was implemented. A typical GUI test starts GIMP, clicks menus and buttons, and then checks the result. These tests run automatically each time we merge contributor changes.

Why we need them

GIMP already has unit tests. A unit test checks one small part of the code, for example how GIMP reads an XCF file. But our unit tests were not opening a real window. So it coult not tell us if a dialog opens, or if a menu item did its job.

Note that GIMP already had tests of GUI code, usually interacting directly with the core code, and sometimes even simulating input devices’ events (pointer movements, clicks, drags…). But nothing can beat interacting with the real interface. Furthermore such legacy tests directly hijacking core code come with their own problems, such as breaking all too often (and not because they detected a bug), all while not being able to detect whole categories of bugs.

UI tests check the program as a whole, in the same way as you use it.

What the tests do

Each test starts a real GIMP and does one small task. Then it reads the result from GIMP. If the result is not correct, the test fails and tells us what went wrong.

We have 13 tests at this time. They check that:

  • GIMP starts and shows its main window.
  • The Welcome dialog opens on the correct tab. It also stays hidden when you turn off “Show on Start”.
  • File > New makes an image with the size you set.
  • File > Export As writes a correct PNG file.
  • Tools > Swap Colors swaps the foreground and background colors.
  • You can type a new foreground color in the Colors dialog.
  • You can add a layer and delete a layer.
  • Undo and Redo work.
  • Zoom In changes the zoom level.
  • A click on a tool button in the toolbox selects that tool. The test then uses the Bucket Fill tool on the canvas.
  • A change in Preferences is saved when you click OK.
  • A menu action, Image > Flatten Image, does its job.

How they work

The tests do not need a screen. Each test starts a small, hidden desktop, runs GIMP in it, and removes it at the end. Because of this, the tests can run on our CI servers, where no screen is available.

To find a button or a menu, the tests do not look at the pixels on the screen. They use the accessibility information that GIMP gives to tools such as screen readers. This has one more good result: when we make GIMP easier to test, we also make it easier to use with a screen reader, hence improve the software accessibility.

The tests use dogtail, a Python tool for UI tests. To run GIMP on a server with no screen, dogtail needed a new feature. We contributed this feature upstream, to dogtail itself, so other projects can use it too.

At this time, the tests run only on Linux (both X11 and Wayland) since dogtail does not support Windows or macOs.

Adding even these few simple tests considerably increases confidence that the GIMP build has worked, and also shows the test infrastructure is working and useful.

Credits

  • Harsh Verma wrote the UI tests and the new dogtail feature.
  • Jehan reviewed the UI tests.
  • Michal Odehnal reviewed the new dogtail feature.

You can read the full change in merge request !2909.

How you can help

13 tests is a good start, but GIMP has many more dialogs and tools. If you want to help, you can write a test for the part of GIMP that you use the most.

We wrote a guide that shows how to write a new test and how to find the cause when a test fails: UI tests on developer.gimp.org.

We hope this work will help us find bugs earlier and keep GIMP working well for everyone.

联系我们 contact @ memedata.com