1

Or from other place..

  • What I want: get all scenario names on start test, but without start all tests.
  • What I tried: by assembly reflection I scanned content, but one contain only feature names and method names. Not scenario names. (from this: Get list of tests in nunit library programmatically without having to run tests) Also exist ScenarioContext, but it contain only current names. Not all existing in testsuite.

What i am using:

  • Specflow for describe.
  • NUnit for run. VS2019.
  • TestRail for result collect. TestSuite contains testName equal test describe in Specflow.

I hope it possible. Thanks to all!

aleksefy
  • 11
  • 3
  • You can have a look at the `.feature.cs` files generated from each feature file. They should be NUnit test classes. You should be able to use class reflection to read the attributes over the class names and methods. – Greg Burghardt Jun 30 '21 at 18:14
  • Thank U,Greg! Yes, I tried get attributes through NUnit class reflection. Here my code: https://pastebin.com/hfve49A2 In **.feature.cs** class generated scenario name contains in `[NUnit.Framework.DescriptionAttribute("First method. SaveForExample")]` I researched and obtain inherinatce `DescriptionAttribute : PropertyAttribute`. https://github.com/nunit/nunit/blob/master/src/NUnitFramework/framework/Attributes/DescriptionAttribute.cs And PropertyAttribute.cs contains `readonly PropertyBag properties = new PropertyBag();` and `property Properties`. But I do`nt have result. =( – aleksefy Jul 02 '21 at 07:25

1 Answers1

0

Ok, I`m finded it!

List<string> scenLst = new List<string>();
try
{
    var assembly = System.Reflection.Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "project.dll"));
    var types = assembly.GetTypes();                    
    foreach (Type t in types){
        foreach (var method in t.GetMethods()){
            foreach (var attributes in tm.GetCustomAttributes())
            {
            if (attributes is DescriptionAttribute){
                var d = propertyList.Properties["Description"][0].ToString();
                if(d != null){
                    scenLst.Add();
                }
            }
        }
    }
}
catch (Exception ex){...}
return scenLst;
}

To get tags use CategoryAttribute (from NUnit).

Kemal Kaplan
  • 932
  • 8
  • 21
aleksefy
  • 11
  • 3