简体   繁体   English

获取使用情况数据以构建单元测试

[英]Get Usage Data to build unit tests

I'm developping a WPF application using the MVVM pattern. 我正在使用MVVM模式开发WPF应用程序。

I would like to be able to collect usage data in order to be able to replay scenario that leads to bugs. 我希望能够收集使用情况数据,以便能够重播导致错误的场景。

I assume that the the Viewmodel is the place to start, because this is where user interraction data comes in. 我认为Viewmodel是开始的地方,因为这是用户输入数据的来源。

My idea is to start by logging all properties and methods calls along with important data. 我的想法是从记录所有属性和方法调用以及重要数据开始。 What do you think ? 你怎么看 ? Any experience to share ? 有经验可以分享吗?

TIA. TIA。

It probably depends on how verbose you need those logs... Logging every single property and method call might have an impact on performance. 这可能取决于您需要这些日志的详细程度。记录每个属性和方法调用可能会对性能产生影响。
Also, when Binding to properties the GetValue gets called directly and not via the CLR property, so you won't really be getting ALL the calls... 同样,当绑定到属性时, GetValue 被直接调用,而不是通过CLR属性被调用 ,因此您将不会真正获得所有调用。

Either way, the concept of logging the ViewModels is a good one. 无论哪种方式,记录ViewModels的概念都是一个很好的方法。 If all your VMs inherit from some sort of ViewModelBase , it'll be easy to implement the logging if you put it there. 如果您所有的VM都继承自某种ViewModelBase ,那么将日志放到那里就很容易实现。

I suggest you start by using a dedicated logging tool such as log4net . 我建议您首先使用专用的日志记录工具,例如log4net Use it for: 使用它:

  • VM Creation 虚拟机创建
  • Calling of important methods 重要方法的调用
  • Exceptions 例外情况
  • etc. 等等

You can always go and log EVERY call to EVERY function, but it might be easier to log way-points along the way instead. 您可以始终记录对EVERY函数的EVERY调用,但是记录沿途的航可能更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM