Search code examples
c#mstestdata-driven-teststestcontext

How to execute code before MSTest TestContext is set


For our data-driven tests we're using Excel files for datasource. Now, because the Excel files are binary data, we had a lot of headaches with git (not being able to diff, files overwritten and implicitly a lot of false positives due to incorrect test data that was actually changed several time).

So, to overcome this I thought that we may use Google Drive to store the datasource and everytime download the Excel file that will be used.

The problem now is that TestContext is set in AssemblyInitialize before I get to download the datasource from Google Drive and therefore it's not able to find it.

Is there a possibility to determine the download of the datasource in the same assembly as the tests? I know that I could create a new solution to set it as a build task before executing the test assembly, however I'm looking for something for neat, if possible.

EDIT: I gave it a try using the option to create a new Console Application project that will be ran as a build task and download the Excel file before executing the tests.

However, it seems that since the Excel file was not added to the Solution it doesn't get picked up by the Datasource attribute.


Solution

  • So the only way to make it work was to create a new console application project that was added as a pre-build task to the data-driven tests project.

    At least this was the initial approach because it caused our solution to have an extra 1-2 mins (depending on the network traffic).

    So I ended creating a new build task in the build system that will handle this.