If you are using Visual Studio Team Services (VSTS) for your continuous integration (CI) you may want to run only specific tests. In the past, I had a project that were dividing tests that needed database and not. One was integration tests, the other one unit tests. In the CI you want only to run unit tests. The reason is that they doesn’t not require any infrastructure like databases, cached, third-party services or external API. That said, if you cannot specify an assembly name (or pattern) how can you tell the CI to run only the unit test?
This is not really obvious from VSTS website what you can put there. The “i” icon gives you some information but this is quite limited. A better user interface (UI) would have been to have a quick cheat sheet available on the “i”. Nevertheless, you can type “TestCategory=YOUR_CATEGORY” where YOUR_CATEGORY is the one defined in the test.
At this point, you are almost done. I didn’t had any test category defined on any test since tests were divided by assemblies before. Now, they are all in the same. The quickest way to add test category to test was to go on each file, open these related to unit test and do a search and replace on open files. The searching query is for [TestMethod]. The replacement is [TestMethod][TestCategory(“UnitTest”)]. From there, you just need to commit and push you change and see the CI running the unit tests.