locked
Tests failing before they are even initialized RRS feed

  • Question

  • I'm working with some data-driven unit tests.

    They reference files that, to begin with, don't exist. (they are referenced using a DataSourceAttribute)

    The ClassInitialize function has methods in it that I want to use in order to generate the files I need before each run of the tests. For some reason, the tests fail before they even get a chance to run, and the files are never made.

    Are the files required to exist before they are referenced in the code? If so, is there somewhere else that I could put my code to ensure I make the files before my tests are run?

    Thursday, June 5, 2014 10:37 PM

Answers

  • You can use a startup script to run a program which will create required files for you. See Test Settings: Setup and Cleanup Scripts.

    You can create another console app which will generate the data files and then call that console app in setup script in testsettings file of your test project.

    On different note, Why is it that the data files are generated every time, that too from withing the test class? Does this generation depend on some other paramters?


    TejasJ.

    • Edited by TejasJ Friday, June 6, 2014 4:47 AM
    • Proposed as answer by Amanda Zhu Tuesday, June 10, 2014 1:39 AM
    • Marked as answer by Amanda Zhu Friday, June 13, 2014 1:46 AM
    Friday, June 6, 2014 4:45 AM

All replies

  • You can use a startup script to run a program which will create required files for you. See Test Settings: Setup and Cleanup Scripts.

    You can create another console app which will generate the data files and then call that console app in setup script in testsettings file of your test project.

    On different note, Why is it that the data files are generated every time, that too from withing the test class? Does this generation depend on some other paramters?


    TejasJ.

    • Edited by TejasJ Friday, June 6, 2014 4:47 AM
    • Proposed as answer by Amanda Zhu Tuesday, June 10, 2014 1:39 AM
    • Marked as answer by Amanda Zhu Friday, June 13, 2014 1:46 AM
    Friday, June 6, 2014 4:45 AM
  • Hi,

    The reason that the file was not created is that VS test engine execute 'DataSourceAttribute' first than ClassInitialize method. Please try Tejas suggestion to create the file. But I still suggest creating the file first outside the test and then use it in test.

    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.

    Friday, June 6, 2014 11:04 AM