samedi 16 janvier 2021

Unit Testing A Class That Use Reflection

I am creating a class called ClassExaminer which uses reflection to read information about properties of the given class. Below is the sample of the class.

public class ClassExaminer<T>
    {
        public bool HasWritableProperty(string name)
        {
            // Some Code to be put in future.
            return true;
        }
    }

The above class takes a generic parameter of the class that is needed to be examined.

My question is when writing unit tests for this class as I can't create a class inside a method, I will have to create a sample scenario class for each test that I write. And then there will be a lot of private sample classes inside the TestFixture. Will that be a good idea and Should I write a single sample class that will include all the scenarios(properties with specific requirements) and write all tests using that class a sample class for the generic parameter to the ClassExaminer class. Do let me know your views on this, thanks.





Aucun commentaire:

Enregistrer un commentaire