等效的 GUI 组件 Swing

发布于 2024-10-31 13:56:24 字数 334 浏览 1 评论 0原文

我有以下问题:给定一个 Swing GUI 应用程序(包括源代码),我如何确定两个组件(例如:JButtons、JList 等)是等效的(对于同一事件执行相同的用户代码)在它们上生成)。

我的观点是,首先他们需要为所有可用事件以相同的顺序拥有相同的侦听器(我只谈论应用程序本身添加的侦听器),然后这些侦听器的代码不得依赖于生成事件的源(因此不应在其代码中调用“Action Command”或 e.getSource())。

这是我正在从事的有关 GUI 应用程序的研究项目,我正在尝试研究如何通过检测等效组件来减少 GUI 测试用例的数量。如果您对此有任何想法(也许我没有考虑到某些事情)请分享。

谢谢。

I have the following question: given a Swing GUI application (source code included), how can I ascertain that two components (e.g: JButtons, JList, etc) are equivalent (in the way that the same user code is executed for the same event generated on them).

My opinion is that first of all they'd need to have the same Listeners in the same order for all available events (I'm talking only about listeners added by the application itself), and then those listeners' code must not depend on the source of the generated Event (so no "Action Command" or e.getSource() should be called in their code).

This is for a research project regarding GUI applications I'm working on, I'm trying to study how you could reduce the number of GUI test cases by detecting equivalent components. If you have any thoughts on this (maybe I'm not taking something into account) please share them.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是有多爱你 2024-11-07 13:56:24

我个人觉得这取决于你对“等效”的定义。根据您的定义,这意味着“当应用程序生成事件时,应用程序中会发生相同的事情”。
但“同样的事情”是指用户的角度还是程序员的角度?

如果是前者,那么这个问题是多余的,因为用户只需要检查不同的动作是否会导致相同的视觉结果来确定它们是否等效。然而,这需要进一步的思考——两个小部件的直接视觉结果可能是相同的,但从长远来看,这些操作对于用户来说可能并不“等同”。例如,您按下按钮 A,您观察 A;但是如果您选择列表 B,您会再次观察 A,而且,可能会发生一些用户未检测到的不明显事件 B。从长远来看,这可能会影响事情。因此,从用户的角度来看,等效性可能是一个棘手的问题。

后一种情况更难分析。正如您所提到的,一种方法可能是它们共享相同的侦听器,即使用相同的方法来处理这两个小部件。他们可以选择使用不同的侦听器,甚至可能使用不同的方法,但如果两种方法本质上遵循相似的逻辑或目的,则它们可能是“等效的”。然而,这可能是特定情况的,并且可能是一个非常微妙的主题(比较方法)。

另一个想法:您还可以选择在小部件上对各种不同的测试和输入进行实验,并得出一些统计值来为您的比较分配确定性度量(例如,这些小部件对于所提供的输入的 80% 以上是等效的)。这可能适用于比较 JTextArea 和 JTextField 等文本输入。

您的假设也可能会影响您对等价性的定义。例如,假设这些输入,A 和 B 是等效的。

这些只是我的一些想法和意见。毕竟,这是一篇研究论文。希望我提供了一些值得深思的东西。

编辑

我认为事件本身的检测是一个微不足道的细节。重要的是事件的处理方式。本质上,您的问题可以归结为:是否有某种方法可以比较特定事件的事件处理程序。老实说,我不确定如何做到这一点(也许比较堆栈,检查代码冗余,检查 is-a 关系)。老实说,我不知道如何进行这样的比较。

Personally, I feel that this depends on your definition of "equivalent". By your definition, this means that "the same thing happens in the application when they generate their events".
But by "same thing", does this refer to the users perspective or the programmers perspective?

If its the former, then the question is redundant, since the user merely needs to check if the different actions lead to the same visual outcome to determine if they are equivalent. However, this is requires further thought- it might be possible that the immediate visual outcome is the same for both widgets, but in the long term, the actions might not be "equivalent" for the user. e.g. you press button A, you observe A; but if you make a list selection B, you observe A again, but also, some non-noticeable event B might happen which is not detected by the user. In the long run, this could affect things. So equivalence from a users perspective might be a tricky issue.

The latter case is harder to analyse. One way could be, as you mentioned, they share the same Listener i.e. the same method is used to handle both widgets. They could alternatively use different listeners, and perhaps even different methods, but if both methods essentially follow a similar logic or purpose, they might be "equivalent". However, this might be case specific and might be quite a nuanced topic (to compare methods).

Another idea: You might also choose to run experiments over various different tests and inputs on the widget and derive some statistical value to assign a certainty measure to your comparison (e.g. these widgets have are equivalent for over 80 percent of the provided inputs). This might apply when comparing text inputs for e.g. JTextArea and JTextField.

Your assumptions might also have a bearing on your definition of equivalence. e.g. assuming these inputs, A and B are equivalent.

These are just a few of my thoughts and opinions. After all, its a research paper. Hope I've provided some food for thought.

EDIT

I am of the opinion that the detection of the event itself is a trivial detail. Its how the event is handled which is important. Essentially your question boils down to: is there some way of comparing the event handler for a particular event. Honestly, I'm not sure how this can be done (compare stacks maybe, check for code redundancy, check for is-a relationships). I honestly don't know how such comparisons can be done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文