Visual studio 2012 如何在CodedUI中设置TestName?
我有一个名为myTestMethod的数据驱动CodedUI测试方法,它使用XML提供输入数据 对于数据集上的每次运行,CodedUI在测试资源管理器中报告如下内容:Visual studio 2012 如何在CodedUI中设置TestName?,visual-studio-2012,coded-ui-tests,Visual Studio 2012,Coded Ui Tests,我有一个名为myTestMethod的数据驱动CodedUI测试方法,它使用XML提供输入数据 对于数据集上的每次运行,CodedUI在测试资源管理器中报告如下内容: Test Passed - myTestMethod (Data Row 0) Test Passed - myTestMethod (Data Row 1) Test Failed - myTestMethod (Data Row 2) <error details> Test Failed - myTestMeth
Test Passed - myTestMethod (Data Row 0)
Test Passed - myTestMethod (Data Row 1)
Test Failed - myTestMethod (Data Row 2) <error details>
Test Failed - myTestMethod (Data Row 3) <error details>
测试通过-myTestMethod(数据行0)
测试通过-myTestMethod(数据行1)
测试失败-myTestMethod(数据行2)
测试失败-myTestMethod(数据行3)
我想知道是否有一种方法可以将测试名称设置为更可识别的名称(可能来自输入数据集本身)
CodedUI似乎使用TestContext.TestName进行此报告,但它是一个只读属性。有没有办法把它放在别的地方
请帮忙。
谢谢
Harit好的,我现在明白你的意思了。我实际上有一个类,我在其中编写一般函数。其中一个是保存我想要的测试结果 我使用基于XML的数据驱动。那么我的雇员1和雇员2是相同测试方法的不同运行 只需找到[TestCleanup()],并在此处调用您需要的保存日志的函数 日志可以csv格式保存,纯文本以分隔;例如,使用StreamWriter
namespace NAME_SPACE
{
[CodedUITest]
public class Program_Something_BlaBla
{
Stopwatch stopWatch = new Stopwatch();
[TestMethod(), Timeout(999999999)]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", PATH_XML, "DATOS", DataAccessMethod.Sequential)]
public void Program_Something_BlaBla_Method()
{
string employe = TestContext.DataRow["EMPLOYE"].ToString();
try
{
//Test actions
...
{
catch (Exception g)
{
...
return;
}
}
#region Additional test attributes
// You can use the following additional attributes as you write your tests:
////Use TestInitialize to run code before running each test
[TestInitialize()]
public void MyTestInitialize()
{
stopWatch.Start();
...
}
//Use TestCleanup to run code after each test has run
[TestCleanup()]
public void MyTestCleanup()
{
stopWatch.Stop();
...
Common.EndTest(employe);
}
#endregion
希望能有所帮助,我不想说这是不可能的,但是测试资源管理器在编译时被填充,数据将在运行时被拉入。我认为这是不可能的。唯一的方法是读取生成的“TRX”文件(因为它是xml),并通过读取CSV替换这些值。可能需要做一个工具,但开销很大。我想你误解了我。我需要根据数据报告每个测试运行的测试名称报告。例如,如果我的testmethod命名为Program_Something_BlaBla_Method,测试数据表示Employee1和Employee2的数据,我需要在测试资源管理器中报告类似的内容:Program_Something_BlaBla_Method_Employee1和Program_Something_BlaBla_Method_2