这可能看起来是一个愚蠢的问题,但我发现自己经常遇到这个问题。
我想写一个简单的应用程序来监控键盘上的输入和我使用鼠标的时间,这样我就可以监控我的计算机的使用情况和工作效率。
考虑以下小黄瓜功能:
Feature: MouseInteractionMonitoring
In order to know when the user is at the computer
As an interaction monitor
I want to be able to be able to monitor when the user moves the mouse在我看来,这似乎是不可测试的。
那么我该怎么做呢?
我是否应该使用抽象层来解决这个问题,方法是编写一个单独的组件来监视鼠标移动,然后将该报告发送给用户交互模块并模拟鼠标移动组件?
如何处理像上面这样的不可测试的代码?
我真的很感谢你在这方面能提供的任何建议。
发布于 2015-06-11 15:24:27
答案通常是以不同的方式思考问题。
例如,我认为您提到的特定功能实际上是非常可测试的,因为可以在代码中移动鼠标,并且您也应该能够触发单击事件。在实际场景中,您必须获得非常具体的内容:
Scenario Outline: Should log mouse movements
Given the computer is <status>
When the mouse moves by more than two pixels
Then a mouse move user interaction is logged
Examples:
| status |
| idle |
| active |
Scenario: should log left-mouse clicks
When the mouse is left-clicked
Then a left-click user interaction is logged..。等。
https://stackoverflow.com/questions/30773041
复制相似问题