Introduction
If you have unit-tests running on each checkin, or you have a lot of unit-tests and you want to improve the time of execution, this article is for you!
I will show you how to implement some changes in your current test project in order to improve execution time locally from Visual Studio, but also in a TFS build pipeline.
Tests Results Before
Before applying the changes, this build step time was taking about 10 minutes.
Tests Results After
After applying the changes, the build step time decreases almost 5 minutes.
Changes to be Applied
You will need to install from nugets two packages in your project MSTest.TestAdapter
and MSTest.Framework
.
You will also need to remove from your project the default installed package "Microsoft.VisualStudio.QualityTools.UnitTestFramework
".
Now, you only need to add the attribute assembly in some class on your unit-test project, in my case, I add it in the BaseTest
class.
The variables Workers
and Scope
can be changed depending on your own customization:
Workers = 0
(use as many threads as possible based on CPU and core count) Workers = X
(X
is number of threads to execute tests) Scope = ClassLevel
(each thread executes a TestClass
you have in your project) Scope = MethodLevel
(each thread executes a TestMethod
)
TFS Build Definition
In the build definition, you just need to update the field "Path to Custom Test Adapters" if your Agent server is using Visual Studio 2015, you need to specify in this field the MSTest.TestAdapter.dll added to the project previously.
To finalize, this change increased the speed in almost 50% of execution time.
History
- 2nd April, 2019: Initial version