Search code examples
unit-testingtfs-2015vnext

How can I run Visual Studio tests in a vNext build as a specific user


Our VNext builds are created using tfs 2015. The Visual Studio Test step is running fine, but for some applications we want to run the unit tests as a specific user.

Is it possible to do this in the "Visual Studio Test" step, or do I need to use a different approach?


Solution

  • From this article: Test agent, Test Controller and MSTEST FAQ (Qustion 21), it should be also applied to VS test.

    Will Test Agents allow you to impersonate another user? Or does the Test Agent always kick of tests as the user its configured start up as?

    There is no built in support for impersonation, so by default tests run under the identity of the test agent. If this is something you really need, you could write a unit test extension that does the impersonation for you.

    So, we can not specify the user in the "Visual Studio Test" step, the test will running with the agent, you can try to change the agent service account to the specific account of the user. Or deploy a new agent to run with the specific account, Reference : Running Unit Tests on different machine during TFS 2015 build