locked
Data Driven Testing with TestInitialize or ClassInitialize RRS feed

  • Question

  • I use CodedUI and MTM for my testing. I am a big fan of data driven testing.  I use data driven at the TestMethod level the most. What I am interested in knowing, is...

    Can I create a DataSource attribute on a TestInitiliaze or ClassInitialize to collect the data I need for all my tests and then use them in the TestMethods?

    We use Modeling from Entity Framework for our coding practices, so it would be nice to let the initializers do the work of collecting the data and putting the data into models, then just pass the models to the tests as needed.  This would prevent the data collection from sucking up so much processing time in the tests.  Giving us a more accurate test result.  Granted, it isn't that much, but it can throw off the test perf results everytime you have to hit a db/spreadsheet/CSV. This process also makes it cleaner when passing data from method to method.  Which helps us to conform to best practices behaviors in coding.

    It also makes sense to pre-load our data prior to testing activity.

    Tuesday, November 25, 2014 12:16 AM

Answers

  • Hi LeHayes2,

    Can I create a DataSource attribute on a TestInitiliaze or ClassInitialize to collect the data I need for all my tests and then use them in the TestMethods?

    Currently using DataSource attribute at TestInitialize and ClassInitialize level is not supported in Visual Studio data driven test, it only can be used at Test Method level. But you can get all data source connection through DataConnection property of TestContext Class in ClassInitialize method.

    If you want to collect the data you need for all your tests in TestInitialize or ClassInitialize, you need write your own C#/VB code to do that as you make it in a normal program, and then you write your own code to put the data into models and pass the data in models to test methods. But in this case, you are not doing data driven tests and you are not able to use the advantage of data driven tests.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Amanda Zhu Monday, December 1, 2014 9:08 AM
    Tuesday, November 25, 2014 6:59 AM

All replies

  • Hi LeHayes2,

    Can I create a DataSource attribute on a TestInitiliaze or ClassInitialize to collect the data I need for all my tests and then use them in the TestMethods?

    Currently using DataSource attribute at TestInitialize and ClassInitialize level is not supported in Visual Studio data driven test, it only can be used at Test Method level. But you can get all data source connection through DataConnection property of TestContext Class in ClassInitialize method.

    If you want to collect the data you need for all your tests in TestInitialize or ClassInitialize, you need write your own C#/VB code to do that as you make it in a normal program, and then you write your own code to put the data into models and pass the data in models to test methods. But in this case, you are not doing data driven tests and you are not able to use the advantage of data driven tests.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Amanda Zhu Monday, December 1, 2014 9:08 AM
    Tuesday, November 25, 2014 6:59 AM
  • If you have nay concern, please feel free to come back.

    Have a nice day:)


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 9:54 AM