Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何动态加载xunit测试?_C#_Visual Studio_Selenium_Ienumerable_Xunit - Fatal编程技术网

C# 如何动态加载xunit测试?

C# 如何动态加载xunit测试?,c#,visual-studio,selenium,ienumerable,xunit,C#,Visual Studio,Selenium,Ienumerable,Xunit,我有一组使用ClassDatadecorator动态加载的测试: using Xunit; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Interactions; using System.Collections.Generic; namespace reviewWebApp.UITests { public class ticketFieldWebAppShould {

我有一组使用
ClassData
decorator动态加载的测试:

using Xunit;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using System.Collections.Generic;

namespace reviewWebApp.UITests
{
    public class ticketFieldWebAppShould
    {
        [Trait("Category", "Smoke")]
        [Xunit.Theory]
        [ClassData(typeof(repositories.readForms))]
        public void LoadForms(string formNo , List<string> elemList)
        {
             
            using(IWebDriver driver = new ChromeDriver())
            {
                driver.Navigate().GoToUrl("http://localhost:61851/");
                DemoHelper.Pause();
                driver.SwitchTo().Alert().SendKeys(formNo);
                driver.SwitchTo().Alert().Accept();
                Actions action = new Actions(driver);
                DemoHelper.Pause();
                action.KeyDown(Keys.Control);
                action.KeyDown(Keys.Alt);
                action.Build().Perform();
                driver.SwitchTo().Alert().SendKeys(elemList[0]);
                driver.SwitchTo().Alert().Accept();
                driver.SwitchTo().Alert().Accept();
            }
        }
    }
}
使用Xunit;
使用OpenQA.Selenium;
使用OpenQA.Selenium.Chrome;
使用OpenQA.Selenium.Interactions;
使用System.Collections.Generic;
命名空间reviewWebApp.UITests
{
公共类ticketFieldWebAppShould
{
[特征(“类别”、“烟雾”)]
[Xunit.理论]
[ClassData(typeof(repositories.readForms))]
公共void加载表单(字符串formNo,列表elemList)
{
使用(IWebDriver驱动程序=新的ChromeDriver())
{
driver.Navigate().gotour(“http://localhost:61851/");
DemoHelper.Pause();
driver.SwitchTo().Alert().SendKeys(formNo);
driver.SwitchTo().Alert().Accept();
动作动作=新动作(驱动);
DemoHelper.Pause();
动作。按键按下(按键。控制);
action.KeyDown(Keys.Alt);
action.Build().Perform();
driver.SwitchTo().Alert().SendKeys(elemList[0]);
driver.SwitchTo().Alert().Accept();
driver.SwitchTo().Alert().Accept();
}
}
}
}
包含数据的类位于单独的文件中:

using System.Collections.Generic;
using System.Collections;

namespace reviewWebApp.UITests.repositories
{
    public class readForms : IEnumerable<object[]>
    {
        public IEnumerator<object[]> GetEnumerator()
        {
            for (int i = 1; i < 3; i++)
            {
                yield return new object[] { "t"+ i, new List<string> { "f", "" } };
            }
        }
        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
    }
}
使用System.Collections.Generic;
使用系统集合;
命名空间reviewWebApp.UITests.repositories
{
公共类readForms:IEnumerable
{
公共IEnumerator GetEnumerator()
{
对于(int i=1;i<3;i++)
{
返回新对象[]{“t”+i,新列表{“f”,“”};
}
}
IEnumerator IEnumerable.GetEnumerator()=>GetEnumerator();
}
}
由于for循环运行了两次,我希望测试资源管理器中的测试数量是两个不同的测试。 然而,在测试浏览器中,我看到一个测试将打开chrome两次。

问题是,如果一个测试失败,我不知道在哪里或哪个,因为只有一个测试。是否可以在动态加载的两个不同测试中分解代码