【问题标题】:How to fetch categories from nunit/xunt tests using powershell?如何使用 powershell 从 nunit/xunt 测试中获取类别?
【发布时间】:2019-09-11 15:17:53
【问题描述】:

是否可以使用 powershell 获取 nUnit/xUnit 类别列表?

实际问题: 我将使用 nunit 或 xunit 的集成测试标记为 Category/Trait。每个类别/特征表示它测试的一个组件(组件是 lambdas/funcs、容器)。我以某种方式获取此组件列表并存储集成测试运行器(管道)和组件之间的关系。

当容器(组件)启动时,会触发事件,并且 lambda 需要知道要运行哪些集成测试以确保完整性。

干杯

【问题讨论】:

    标签: powershell lambda nunit distributed-computing xunit


    【解决方案1】:

    这是来自TestCentric GUI 的一些代码,它收集了所有类别以供显示。

        public IList<string> GetAvailableCategories()
        {
            var categories = new Dictionary<string, string>();
            CollectCategories(Tests, categories);
    
            var list = new List<string>(categories.Values);
            list.Sort();
            return list;
        }
    
        private void CollectCategories(TestNode test, Dictionary<string, string> categories)
    
        {
            foreach (string name in test.GetPropertyList("Category").Split(new[] { ',' }))
                if (IsValidCategoryName(name))
                    categories[name] = name;
    
            if (test.IsSuite)
                foreach (TestNode child in test.Children)
                    CollectCategories(child, categories);
        }
    
        public static bool IsValidCategoryName(string name)
        {
            return name.Length > 0 && name.IndexOfAny(new char[] { ',', '!', '+', '-' }) < 0;
        }
    

    我看到有两种方法可以去这里...

    1. 使用此代码创建一个写出类别列表的 C# 程序。

    2. 在 Powershell 中模拟此代码。

    在任何一种情况下,您都需要直接或通过引擎 API 引用 NUnit 引擎。

    显然,nunit3-console.exe 可以以相同的方式显示类别列表,但这不是当前的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2010-12-13
      相关资源
      最近更新 更多