A loooong time ago in Visual Studio 2010 Microsoft introduced a great new feature Test Impact Analysis. Test Impact Analysis tries to predict based on your code changes which tests should be executed.
In more recent versions of Visual Studio this feature disappeared…until now. Version 2 of the Visual Studio Test task reintroduces the “Run only impacted tests” checkbox. Checking this checkbox will automatically configure the Test Impact data collector to identify and run only the impacted tests.
Remark: If you don’t see this option, check that you are not still using version 1 of the Visual Studio Test task:
More information: https://blogs.msdn.microsoft.com/devops/2017/03/02/accelerated-continuous-testing-with-test-impact-analysis-part-1/