I'm trying to determine the considerations that should be made when writing tests that are going to run under vstest.console.exe
.
Example 1: Let's say that I have two tests both of which rely on MyClass.Singleton.Counter
having a value of zero. Now let's say that we hire a new intern that inadvertently increments that value in a test that he writes. If this new test runs before the older two unit tests. Those two unit tests would fail if the tests are run in the same process (and nothing resets the counter value).
Example 2: Let's say I have two integration tests that hit the same DB. Both of these tests record the value of a counter as it exists in the DB, increment the counter, and then read the counter from the DB, asserting that it's value is 1 higher than when originally read. If both these tests run in parallel, we have a race condition.
With the end goal of trying to understand the considerations developers should keep in mind when writing tests that will run under vstest.console.exe
specifically, what is its execution model?
NOTE: I'm not interested in best practices, only in understanding the execution model of vstest.console.exe
in the ways that affect the outcomes of tests.
Relevant Considerations:
- If
project1.dll
andproject2.dll
are passed to the console, and each has dependencies on conflicting versions of dependent assemblies, how will the project test files execute successfully? - Is each test file (i.e., dll) given its own process?
- Is each test file (i.e., dll) given its own AppDomain within a single process?
- What is the current working directory under which each test file will be executed?
- Will the tests be executed serially or in parallel?
- Is the test execution order deterministic?
- How much control do different test adapters have over the relevant behaviors?
- What are the default behaviors when no
.runsettings
file nor test adapter are specified?
Relevant Background Information:
(1) The vstest.console.exe documentation for /InIsolation
states that it "Runs the tests in an isolated process."
I would infer from the above that a single process is created in which ALL test files passed to the test runner will execute, but that may not be accurate.
(2) vstest.console.exe
can take multiple test "files" on the command line, which are DLLs that may reference different projects in different directories.
(3) By providing a *.runsettings
file, a test adapter can be used to execute the tests.