题
我想可以添加一个"信息"一部试验,这样,它实际上出现在TestResult.xml 文件产生的呢?例如,这是目前生成:
<results>
<test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" />
</results>
我希望能够有一个额外特性(或节点可以视情况),例如:
<results>
<test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" message="Tested that some condition was met." />
</results>
这个想法是,"信息"将以某种方式进行定义内的测试方法本身(在我的情况下,产生在运行时间)。是有一个酒店的地方,我缺少能够做到这样的事情?
解决方案
这可能是缺点,但如何命名的试验使它们表示什么他们测试-那么你甚至可能不需要的信息。
如果这证明是绝对必要的,我想你会需要产生自己的testrunner会(掉我的头顶)读取额外的属性关闭的测试用例,并附上它的输出。
其他提示
在最近关释放你可以这样做:
Assert.AreEqual(250.00, destination.Balance, "some message here");
这里的"一些消息在这里"可能是恒定的消息或产生的消息在运行时并存储在一串的变量。这些信息将仅仅出现在的输出,然而如果断言失败。但是,通常只需的有关信息失败测试所以我建议建立一个串通过增加每个以前的消息然后使用那个字符串变量的消息在所有的你的断言。这可以让你得到所有你需要的信息来自失败的试验。
你可以使用的TestContext容易地编写出来的任何消息你想要的。这里是我设置。
我每次试验是继承了一个testbase类。这除去多余的代码。
[TestFixture]
public class TestBase
{
public IWebDriver driver;
//[OneTimeSetUp] and [OneTimeTearDown] go here if needed
[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);
}
}
你可以看看底部的两个职能写出来的任何信息或错误在上述TestContext.这将工作很好地与parallizable测试。
然后我就可以使用父类设置我的测试,并写信给我的控制台。
//Role Management
public class RoleManagementTests : TestBase
{
[TestCase]
public void RoleManagement_7777_1()
{
Comment("Expected: User has the ability to view all roles in the system.");
//Test goes here
}
}
现在你可以看到的结果在输出(Visual Studio),并在TestResult.xml 使用关控制台运行程序。
不隶属于 StackOverflow