简体   繁体   English

检测我的测试是否在Visual Studio Team Services上运行

[英]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. 我为正在使用的API编写了很多集成测试。

If I run the integration tests locally I want to self host the API and run the integration tests against it. 如果我在本地运行集成测试,则希望自行托管API并对其进行集成测试。

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. 但是,我在VS Team服务上有一个构建定义,该定义在API部署后运行集成测试,我想针对已部署的API运行测试,但是要做到这一点,我必须更改代码,以使其不再自行托管并而是针对已部署的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". 如果您使用VSTS托管构建代理程序来运行构建和测试,则这些代理程序的计算机名称的格式应为“ TASKAGENTX-XXXX”。 You can use it (Environment.MachineName) to determine if the test is ran on VSTS or your local machine. 您可以使用它(Environment.MachineName)来确定测试是否在VSTS或本地计算机上运行。

By the way, what is the difference between the testing run on your local machine and VSTS? 顺便说一句,在本地计算机上运行的测试与VSTS有什么区别? Is it just a different URL? 它只是一个不同的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. 如果是,则可以将配置文件添加到项目中,并更新测试以读取配置文件中的URL进行测试。 And then use SlowCheetah to perform a transformation to switch the URL when build and test from VSTS. 然后从VSTS进行构建和测试时,使用SlowCheetah进行转换以切换URL。

Just probe for one of the VSTS predefined build variables . 只需探查VSTS预定义的构建变量之一即可 For example: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Visual Studio Team Services通过内存中的SQL数据库运行单元/集成测试 - Running Unit / Integration tests through an in-memory SQL database using Visual Studio Team Services MSTest-使用Visual Studio服务(TFS和持续集成)运行测试 - MSTest - Running tests using visual studio services (TFS and Continous Integration ) 单元测试在Visual Studio Team Services上失败由于写入权限而构建运行器? - Unit Tests Failing on Visual Studio Team Services Build runner due to write permissions? 检测visual studio是否正在运行 - Detect if visual studio is running Visual Studio Team Services程序集版本控制 - Visual Studio Team Services Assembly Versioning Visual Studio Team Services-将附件附加到工作项 - Visual Studio Team Services - Attaching an attachment to a workitem MVC 5构建在Visual Studio Team Services上失败 - MVC 5 build failing on Visual Studio Team Services Visual Studio Team Services使用外部dll构建 - Visual Studio Team Services build with external dll 扩展Visual Studio Team Services(在TFS上在线) - Extend Visual Studio Team Services (was TFS Online) 从 WebService 连接到 Visual Studio Team Services - Connect to Visual Studio Team Services from WebService
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM