如何动态加载xunit测试?

问题描述

我有一组使用 ClassData装饰器动态加载的测试:

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();
            }
        }
    }
}

具有数据的类位于单独的文件

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();
    }
}

由于for循环执行了两次,因此我希望测试浏览器中的测试数量为2个不同的测试。 但是,在测试浏览器中,我看到1个测试将打开chrome两次。

enter image description here

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)