仅更改私有成员变量的单元测试函数?
我目前正在为我的项目中使用 Prism 和 MVVM 模式的 ViewModel 编写单元测试。
我的视图主要由一个 ItemsControl 组成,它对不同的鼠标事件(LeftMouseButtonDown、LeftMouseButtonUp 等)做出反应。 当这样的鼠标事件发生时,EventArgs 和其他一些粘合信息将被传递给 ViewModel,并调用适当的方法(MouseMove 事件 --> OnMouseMove 方法)。
通过这种方式,我实现了一种拖动以前添加到 ItemsControl 的项目的方法。 这是通过在 OnMouseLeftButtonDown 方法中设置两个成员变量“movingObject”和“gripPoint”并在 OnMouseLeftButtonUp 方法中将变量设置为 null 来实现的。
现在出现的问题是我是否应该对这些函数(LeftButtonUp、LeftButtonDown)进行单元测试。 理论上,它们是由“外部”世界访问的(——>而不是 ViewModel 本身),因此值得测试,但我应该如何测试(在我看来)不值得公开的私有变量的变化访问器(出于低级目的而存在)?
提前致谢!
I am currently writing unit tests for a ViewModel in my project that uses Prism and the MVVM pattern.
My view mainly consists of an ItemsControl that reacts to different mouse events (LeftMouseButtonDown, LeftMouseButtonUp etc.). When such a mouse event happens the EventArgs and some other glue info is handed to the ViewModel and an appropriate method is called (MouseMove event --> OnMouseMove method).
This way I implemented a way to drag items that were formerly added to the ItemsControl around. That happens through setting two member variables "movingObject" and "gripPoint" in the OnMouseLeftButtonDown method and setting the variables to null in the OnMouseLeftButtonUp method.
The question that now arises is if I should unit test these functions (LeftButtonUp, LeftButtonDown). In theory they are accessed by the "outer" world (--> not by the ViewModel itself) and therefore deserve a test but how should I test the change of an private variable that (in my opinion) doesn't deserve a public accessor (for the low level purpose it exists)?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建访问器可能适合您。 请参阅以下链接:
http://msdn.microsoft .com/en-us/library/ms184807(VS.80).aspx
http://www.xheo.com/Blog/post/Manually-creating-a-Visual-Studio-accessor-file.aspx
Creating accessors could work for you. Please see the links below:
http://msdn.microsoft.com/en-us/library/ms184807(VS.80).aspx
http://www.xheo.com/Blog/post/Manually-creating-a-Visual-Studio-accessor-file.aspx