OpenCover的运行时间比nunit

OpenCover的运行时间比nunit

本文介绍了OpenCover的运行时间比nunit-console更长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为此项目添加单元测试: https://github.com/JimBobSquarePants/ImageProcessor

I'm trying to add unit tests to this project: https://github.com/JimBobSquarePants/ImageProcessor

运行单元测试时,它们可能需要1到2分钟才能运行(这是一个图像处理库,我并不认为它们会如此之快).

When running the unit tests, they take maybe 1 or 2 minutes to run (it's an image processing library, and I don't expect them to be insanely fast).

问题是,当我通过这些测试运行OpenCover时,它们需要大约20分钟才能运行.

The problem is that when I run OpenCover over these tests, they take something like 20 minutes to run.

当前单元测试的要点是,有一堆测试图像,每个单元测试(实际上更像是集成测试)读取每个图像,并对它们运行一堆效果.

The gist of the current unit tests is that there are a bunch of test images, and each unit test (more like integration tests, actually) reads each image, and runs a bunch of effects on it.

我猜我做错了什么,但是怎么办?为什么在OpenCover上花费的时间比NUnit运行器花费的时间多?

I'm guessing that I'm doing something wrong, but what? Why does it takes so much more time on OpenCover than NUnit runner ?

推荐答案

OpenCover 可衡量您的IL程序集(可以找到它的PDB文件-因为这是文件位置信息所在的位置),然后对于每个序列点(可以考虑放置断点的位置),每个条件分支路径都将引起一个动作进行注册访问(并增加访问次数).

OpenCover instruments the IL of your assemblies (for which it can find a PDB file - because that is where the file location information is kept) and then for each sequence point (think of places you can put a break point) and each conditional branch path will cause an action to register the visit (and increase the visit count).

对于算法代码,您会发现在繁重的集成测试中运行覆盖率是一个性能问题,因此请确保仅在严格的集成测试或单元测试中运行覆盖率,例如在您的情况下,请使用较小的图像(如先前建议的那样),以测试代码的正确性.

For algorithmic code you will find running coverage on heavy integration tests will be a performance issue so make sure you only run coverage on tight integration tests or on unit tests e.g. in your case perhaps use small images (as previously suggested) that can test the correctness of your code.

您尚未描述过OpenCover的运行方式(或哪个版本-我将假定为最新版本),但请确保您已排除测试程序集,而仅对目标程序集进行了检测.

You haven't described how you are running OpenCover (or which version - I'll assume latest) but make sure you have excluded the test assemblies and are only instrumenting the target assemblies.

最后,OpenCover使用了几个队列和线程,但是如果由于循环等原因向它扔很多数据,那么它将需要时间来处理数据,因此它在具有4个或更多内核的计算机上工作得更好.在运行测试时,请查看任务管理器,看看发生了什么.

Finally OpenCover uses a few queues and threads but if you throw a lot of data at it due to loops etc then it will need time to process the data so it works much better on machines with 4 or more cores. When you are running your tests have a look at the task manager and see what is happening.

这篇关于OpenCover的运行时间比nunit-console更长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:44