1

I am calling Unit Test Methods from another project to a window form list. But I am getting 'ToString','Equals' etc. along with test methods.

This is my code:

public Form1()
{
    InitializeComponent();
    FillListView();
}

public void FillListView()
{
    MethodInfo[] methodInfoFT = typeof(UnitTestProject1.UnitTest1)
        .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod);

    foreach (MethodInfo methodInfo in methodInfoFT)
    {
        listBox1.Items.Add(methodInfo.Name);
    }
}

This is what I get:
Image

David L
  • 32,885
  • 8
  • 62
  • 93

1 Answers1

0

You need to use the DeclaredOnly binding flag to ensure that you only retrieve the methods defined in the class itself.

 MethodInfo[] methodInfoFT = typeof(UnitTestProject1.UnitTest1)
    .GetMethods(BindingFlags.Public | BindingFlags.Instance | 
                BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly);
David L
  • 32,885
  • 8
  • 62
  • 93