Reputation: 115
basically I am running a set of coded ui tests using MStest.
I am trying to write a custom log file while the tests are running.
For instance at the end of every test, if the test has passed I want to add a line to a text file that says "Test has passed"
This would preferable go out to a TXT file. and by extension i will eventually be outputting this to an email but that isnt needed right now.
On a basic level at the end of each test i was trying this
if (this.testContextInstance.CurrentTestOutcome.Equals(true))
{
string lines = "Passed.";
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
file.WriteLine(lines);
file.Close();
}
else
{
string lines = "Failed.";
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
file.WriteLine(lines);
file.Close();
}
}
But I don't fully understand the CurrentTestOutcome method.
At the moment i'm not getting any file output at all.
Upvotes: 0
Views: 1550
Reputation: 14037
CurrentTestOutcome
is an enum see http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcontext.currenttestoutcome.aspx and http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.unittestoutcome.aspx . So I am not sure what the this.testContextInstance.CurrentTestOutcome.Equals(true)
of the question achieves.
Something like the following should show what you want:
string lines = "Failed.";
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
file.WriteLine(this.testContextInstance.CurrentTestOutcome.ToString());
file.Close();
Upvotes: 1