Reputation: 555
we are working with MSTest and Selenium to run web tests. Right now we are trying to make the log more understandable and for that we would like to log each method name that the test has executed.
We are using VS2015 update 3 and MSTest 1.4
[TestClass]
public class Test1: TestBase
{
[TestMethod]
public void TEST_Method1()
{
driver.Url = targetURL
loginPage.Login(USER, PASSWORD);
homePage.GoToGraphics();
homePage.GoToUserSearch();
searchBI.Click_Calendar();
searchBI.Select_November();
...
}
}
We would like the log to print
Starting TEST_Method1()
Executing loginPage.Login()
Executing homePage.GoToGraphics()
Executing homePage.GoToUserSearch()
Executing searchBI.Click_Calendar()
Executing searchBI.Select_November()
...
Upvotes: 1
Views: 645
Reputation: 542
The code snippet below captures the current method name and stores it in the methodName variable:
var currentMethod = MethodBase.GetCurrentMethod();
The currentMethod variable contains several properties, including the name of the current method.
You can encapsulate this in another class to expose this to your test execution only, or use a regular Logging library to log it to a console or the output window.
Upvotes: 1