简体   繁体   中英

Detect if my tests are running on Visual Studio Team Services

I've wrote a lot of integration tests for an API I'm working on.

If I run the integration tests locally I want to self host the API and run the integration tests against it.

However I have a build definition on VS Team services that runs the integration test after the API was deployed, I want to run the tests against the deployed API, but to do that I have to change my code so it no longer self host it and instead tested against the deployed API.

Is there a way to detect at runtime where my tests are being run?

Thanks

If you are using VSTS Hosted Build agent to run the build and test, the machine name of these agents has a format like "TASKAGENTX-XXXX". You can use it (Environment.MachineName) to determine if the test is ran on VSTS or your local machine.

By the way, what is the difference between the testing run on your local machine and VSTS? Is it just a different URL? If yes, you can add a config file to your project and update your tests to read the URL in the config file for testing. And then use SlowCheetah to perform a transformation to switch the URL when build and test from VSTS.

Just probe for one of the VSTS predefined build variables . For example:

if (Environment.GetEnvironmentVariable("SYSTEM_DEFINITIONID") != null) 
{
    Console.WriteLine("Running from VSTS...");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM