The current test run creates a unique directory for running tests and storing the generated reports (.trx) files.
In effect, additional inputs and outputs (especially, in case of data driven unit tests) can be persisted in these unique directories during test runs. In addition, unit testing process has complete access in these directories. So, it would be consistent while running the tests in any machines (e.g., in build machines or in local development environments).
TestContext, we can get the path of the directory related to the current test run as follows.
string testDirectory = TestContext.TestDir;
We can get the deployment directory and the directory that contains logs as follows.
string deploymentDirectory = TestContext.TestDeploymentDir; string logDirectory = TestContext.TestLogsDir;
To sum up, this post has described how we can get/set several important properties from
TestContext. In the next post, we show how we can use it for performance measurement.
Other posts in this series includes:
On Unit Testing:
Usage of TestContext: