Recently, when creating a Test Assemblies
tasks performing integration tests, I wanted to be able to use VSTS variables in order to define context (connection string, etc) and not storing the parameters in source repository.
- better flexibility when updating parameters
- not storing password or sensible information in source code
- consistent way of handling our parameters with our VSTS builds
This could be easily achieved by overriding TestRun Parameters
Unfortunately, this mechanism has a huge drawback: if your value contains semi colons, it won't be correctly transfered to test runner and will be truncated. This is quite problematic for connection string for instance.
Browsing internet didn't provide any information or way of protecting the value. I end up creating a stack overflow post 1 and finally 10 days later create a premier ticket at Microsoft. In the meantime someone else raised the issue on official github 2 without answer so far.
Microsoft suggested to split each parameters containing semi colons into chunks without and concatenate them afterward in the test source code.
However it contains 2 major drawbacks
- unit test has to be updated and it increase the number of parameter (clearness, etc)
- it's not working when you don't know the number of chunk in advance (kind of happening often on SQL connection strings for examples)
Another approach I've tried is to use a powershell tasks which read environments variables and then overwrite the XML value of runsettings file. Not perfect but do not requires to change source code waiting for an official solution. The powershell script is quick & dirty, no error management (runsettings not found, XML parameter not found, etc).
I've prefixed our parameter with "__" in order powershell script being able to spot correct variables
use at your own risk :)
You have to configure the -RunSettingsPath
parameter pointing to your runsettings file.