{"id":10071,"date":"2015-09-04T06:23:00","date_gmt":"2015-09-04T06:23:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2015\/09\/04\/supplying-run-time-parameters-to-tests\/"},"modified":"2022-08-02T03:17:10","modified_gmt":"2022-08-02T11:17:10","slug":"supplying-run-time-parameters-to-tests","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/supplying-run-time-parameters-to-tests\/","title":{"rendered":"Supplying Run Time Parameters to Tests"},"content":{"rendered":"<p>Tests broadly classified as integration tests or functional tests are often in need to connect to external app resource (web application, API front end, or a DB tier) to drive validations. Maintaining lifecycle of such tests from the environment where it\u2019s authored (dev machine with VS) to all the other places where they might be consumed (as part of Build\/CI Tests, Build-Deploy-Test workflow, Release workflow) is quite challenging.<\/p>\n<p>As a classic example, consider following piece of functional validation code:<\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/09\/2630.1.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>To effectively reuse such tests throughout the lifecycle it\u2019s important that we provide tooling flexibility for connecting tests to external app resources such as <em>appUrl<\/em> in the example above. In Visual Studio 2015, the ***TestRunParameters ***section in RunSettings file is defined to address this need.<\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/09\/6518.2.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>This value can then be used in tests using TestContext.Properties. Currently, this functionality is only available in MSTest framework.\u00a0<\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/09\/55187.3.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>For CI, BDT and Release workflows, we have added the ability to override the value of parameters declared in the runsettings file with those supplied at runtime. These values can be passed to the Visual Studio Test task or Visual Studio Test using Test Agent task using the Override TestRun Parameters field.<\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/09\/7633.4.png\" alt=\"\" border=\"0\" \/><\/p>\n<p><em>Figure 1: Specifying value of appUrl in the VSTest task<\/em><\/p>\n<p>\u00a0<\/p>\n<p>So as to not hardcode the value in the task itself, you can declare a Build variable and then use that at all places in the workflow where you need it.<\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/09\/2045.5.png\" alt=\"\" border=\"0\" \/><\/p>\n<p><em>Figure 2: Declaring &#8220;Deployment URL&#8221; as a Build variable<\/em><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/09\/7713.6.png\" alt=\"\" border=\"0\" \/><\/p>\n<p><em>Figure 3: Using variable in \u2018Visual Studio Test using Test Agent\u2019 task for a BDT workflow<\/em><\/p>\n<div>\n  \u00a0\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Tests broadly classified as integration tests or functional tests are often in need to connect to external app resource (web application, API front end, or a DB tier) to drive validations. Maintaining lifecycle of such tests from the environment where it\u2019s authored (dev machine with VS) to all the other places where they might be [&hellip;]<\/p>\n","protected":false},"author":176,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,252],"tags":[],"class_list":["post-10071","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-testing"],"acf":[],"blog_post_summary":"<p>Tests broadly classified as integration tests or functional tests are often in need to connect to external app resource (web application, API front end, or a DB tier) to drive validations. Maintaining lifecycle of such tests from the environment where it\u2019s authored (dev machine with VS) to all the other places where they might be [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/10071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/176"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=10071"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/10071\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=10071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=10071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=10071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}