Reputation: 4473
Is there way to automate reporting of each test run?
Now I do this
[TestMethod]
public void Test1()
{
ReportTestStarted("Test1");
// do test like
Assert.IsTrue(true,"Fake good test");
ReportTestFinshed("Test1");
}
with assumption that when test started it should be finished then it is good. ReportTest*() collects all results and then stores them somehow.
I hope that it is possible to use Attributes and update [TestMethod] so it will do such work automatically. Any ideas?
Update: Thanks for @Richard's and @Scott hints I had figured out that I can use this code and know result based on this link
public TestContext TestContext { get; set; }
[TestCleanup]
public void CleanupTest()
{
Console.WriteLine(
"TextContext.TestName='{0}' {1} ",
TestContext.TestName,
(Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome.Passed==TestContext.CurrentTestOutcome?"Pass":"Fail"));
}
Upvotes: 0
Views: 1653
Reputation: 4473
Thanks for comments I have my answer:
public TestContext TestContext { get; set; }
[TestCleanup]
public void CleanupTest()
{
Console.WriteLine(
"TextContext.TestName='{0}' {1} ",
TestContext.TestName,
(Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome.Passed==TestContext.CurrentTestOutcome?"Pass":"Fail"));
}
It provides access to the test name and test result which I can use and store in any way. Most important - I do not have to touch my TestMethods. This approach collects and reports all result without adding extra lines of code to each TestMethod.
Upvotes: 1