I am quite new to visual studio. I am having visual studio community 2015.
What I would like to do is when outputting specific data in my unittest with MSTest, I would like to save the output into a file.
I have seen that at each running test, a folder is generated automatically in TestResuls/Deploy_username date hour/out
. I am looking for a way to save the tests output in that folder.
Is this possible or is there other ways to copy the files or report my data? I have looked at these following links: https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute.aspx
https://msdn.microsoft.com/en-us/library/ee256991.aspx
DeploymentItem not deploying files
Generating Unit Test Reports in Visual Studio 2013
None of these links helped me in achieving what I wanted.
Thank you in advance for your help.
On the File menu, select New > Project, or press Ctrl+Shift+N. On the Create a new project page, type unit test into the search box. Select the project template for the test framework that you want to use, for example MSTest Test Project or NUnit Test Project, and then select Next.
I will not explain how File Output is handled in .Net, I presume you have this Knowledge.
If you have a TestClass
declared with Attribute [TestClass]
you can add a public Property TestContext
of Type TestContext
(see MSDN), which will get set by MSTest while executing the Test.
There you have the Properties TestResultsDirectory
(which typically leads to the "IN" Folder) and TestDeploymentDir
(which typically leads to the "OUT" Folder) .
e.g.: TestContext.TestResultsDirectory
would lead to "D:\Visual Studio 2015\Projects\UnitTestProject1\TestResults\Deploy_user 2017-02-23 07_37_49\In"
If you need the TestContext earlier then in the [TestMethod] you need to use a public static void TestInit(TestContext testContext)
Method in your TestClass, so you get the Instance of the TestContext when your Class got created.
There are also Properties like TestLogsDir, TestDir which are deprecated, you can read in the MSDN docs about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With