Search code examples
c#unit-testingstatic-membersmultiple-projects

Static variable across tests in different test projects


I have 3 projects in my Visual Studio solution: 1 shared library project, 1 unit test project (mostly Selenium WebDriver tests), and 1 coded UI test project (I had a hard time combining my unit tests and coded UI tests into 1 project - so we have 2). I have a static class with a static property in the shared library project called Globals.Status.

I have one test case where it requires work done in both a broswer (the Selenium unit test) and a desktop app (the coded UI test). The Selenium unit test changes this static Status variable. The coded UI test (in the coded UI project) needs to read this updated Status variable. When I run these 2 tests consecutively, the variable is NULL when the coded UI test is invoked.

I have the coded UI test project referencing both the shared library project and the unit test project, but evidently this is not enough. What do I need to do to make this work?

Thanks for any insight!


Solution

  • You need to back your property with data that has been persisted outside of the application (more specifically, outside of the executing assembly's memory space).

    There are a few reasonable ways you could do this. AppFabric Cache, Redis, or maybe Memcached come to mind.