Can I set TestContext.DataConnection at runtime? RRS feed

  • Question

  • I wanted to set the DataConnection for the TestContext object in my test dynamically based on certain conditions. Is it possible?

    Actually, there are two files which I am using to conduct my tests. One file contains the data required for the test and the second file which contains the login information. The reason for this is that the test requires logging in with usernames that have different privileges. And I do not want to store the login credentials as well as the data in one file because in that case I will have to store the credentials in every file which is used by different tests.

    So, is there any way whereby I can open connections during a test and use the data, then open another connection and use the data from tht connection?

    Right now I have resorted to using the configuration file for my login credentials as they do not change for all my tests. But I thought I will clear my query. :)

    • Edited by Pradosh Manerkar Friday, August 6, 2010 10:17 AM Typo
    • Moved by Mathew Aniyan MSFT Monday, August 9, 2010 11:02 PM Question on the base framework feature of data driving and test context. (From:Visual Studio UI Automation Testing (includes CodedUI))
    Friday, August 6, 2010 10:15 AM


  • Hi Pradosh,

    I think you are following the right approach here by storing the credentials in the config. Why do you want to store them in the datasource. Datasource is used when you want to iterate your test for multiple input rows. So if your datasource has 10 input rows, your test will execute 10 times. I am sure your login credentials wouldnt me as many as test data.

    However, there is a feature in web tests where you can have multiple data sources and it comes handy where different requests need different datasources. It would be great to have such a feature in unit tests where you can create multiple transactions (Begin/End Timer) and associate different datasource for each transaction.




    Tuesday, August 17, 2010 2:36 AM