Nunit获取测试名称

时间:2016-09-25 12:08:10

标签: c# nunit .net-assembly

我想问一下是否有办法进行所有测试' TestFixturesetup中的名称,我获取所有测试名称,并将它们放在一个字符串列表中,例如??

我已经尝试过这个解决方案,但它没有和我合作,我无法解决它给我的错误

  

加载程序集时拒绝访问

Assembly a = Assembly.LoadFrom("E:/Visual Studio 2013/Tests_Names/Tests_Names/bin/Debug/Tests_Names.dll");


        // Foreach public class that is a TestFixture and not Ignored
      foreach (var c in a.GetTypes()
               .Where(x => x.IsPublic
               && (x.GetCustomAttributes(typeof(NUnit.Framework.TestFixtureAttribute)).Count() > 0)
               && (x.GetCustomAttributes(typeof(NUnit.Framework.IgnoreAttribute)).Count() == 0)))
        {

                // For each public method that is a Test and not Ignored
                foreach (var m in c.GetMethods()
                                   .Where(x => x.IsPublic
                                   && (x.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute)).Count() > 0)
                                   && (x.GetCustomAttributes(typeof(NUnit.Framework.IgnoreAttribute)).Count() == 0)))
                {

                    // Print out the test name
                    Tests_Names.Add(m.Name);
                    // Alternately, print out the command line to run test case using nunit-console
                    //Console.WriteLine("nunit-console /run:{0}.{1} {2}", c.ToString(), m.Name, assemblyName);
                }

        }

0 个答案:

没有答案