TestContext, , . .
Each of my tests inherits from the testbase class. This removes redundant code.
[TestFixture]
public class TestBase
{
public IWebDriver driver;
[SetUp]
public void Setup(){
driver = Shortcuts.SetDriver("my browser");
}
[TearDown]
public void TearDown()
{
driver.Quit();
Comment("@Result: " + TestContext.CurrentContext.Result.Outcome.ToString());
}
public void Comment(string _comment)
{
TestContext.Out.WriteLine(_comment);
}
public void Error(string _error)
{
TestContext.Error.WriteLine(_error);
}
}
You can see that the bottom two functions write out any message or error in the specified TestContext. This will also work well with parallelized tests.
Then I can use this parent class to configure my tests and write to the console.
public class RoleManagementTests : TestBase
{
[TestCase]
public void RoleManagement_7777_1()
{
Comment("Expected: User has the ability to view all roles in the system.");
}
}
Now you can see the results in the results (Visual Studio) and in TestResult.xml using the NUnit Console Runner.
source
share