Visual Studio单元测试在TFS Build上运行较慢

时间:2021-04-30 15:39:57

My project has 1000+ unit tests that, in a local machine, all run in less than 10 seconds. But when they run on TFS Build, some tests run significantly slower than others. 3 of them run in about 1-2 minutes, other 4 in 5-30 seconds, and the others in fractions of a second. I've noticed that all those slower tests use fakes from Microsoft Fakes, and each one of them is the first to run in it's class. But a lot of the other tests also use fakes (some more intensively) and run in regular time. I would like to know what may be causing that slowdown and how can I fix it.

我的项目有1000多个单元测试,在本地机器上,所有测试都在不到10秒的时间内完成。但是当他们在TFS Build上运行时,某些测试的运行速度明显慢于其他测试。其中3个在大约1-2分钟内运行,其他4个在5-30秒内运行,其他的则在几分之一秒内运行。我注意到所有那些较慢的测试都使用来自Microsoft Fakes的假货,而且每一个都是第一个在它的类中运行的。但是很多其他测试也使用假货(一些更密集)并且定期运行。我想知道可能导致这种减速的原因以及如何解决这个问题。

Edit: I've noticed that every slower test runs after a mockless test. Maybe that slowdown is caused by the initialization of the ShimsContext. In my test classes, the ShimsContext is created and disposed on TestInitialize and TestCleanup methods. Does that affects significantly the performance?

编辑:我注意到,在无模拟测试之后,每个较慢的测试都会运行。也许这种减速是由ShimsContext的初始化引起的。在我的测试类中,ShimsContext是在TestInitialize和TestCleanup方法上创建和处理的。这会对性能产生重大影响吗?

1 个解决方案

#1


Refer following links : https://softwareengineering.stackexchange.com/questions/184834/how-do-we-make-unit-tests-run-fast

请参阅以下链接:https://softwareengineering.stackexchange.com/questions/184834/how-do-we-make-unit-tests-run-fast

http://arlobelshee.com/the-no-mocks-book/

The links say that making tests fast can be hard. Decoupling is key. Mocks/fakes are OK, but one can do better by refactoring to make mocks/fakes unnecessary.

链接说快速进行测试可能很困难。解耦是关键。模拟/假货是可以的,但是通过重构来制作模拟/假货可以做得更好。

#1


Refer following links : https://softwareengineering.stackexchange.com/questions/184834/how-do-we-make-unit-tests-run-fast

请参阅以下链接:https://softwareengineering.stackexchange.com/questions/184834/how-do-we-make-unit-tests-run-fast

http://arlobelshee.com/the-no-mocks-book/

The links say that making tests fast can be hard. Decoupling is key. Mocks/fakes are OK, but one can do better by refactoring to make mocks/fakes unnecessary.

链接说快速进行测试可能很困难。解耦是关键。模拟/假货是可以的,但是通过重构来制作模拟/假货可以做得更好。