How do you unit test private methods?

前端 未结 30 1851
无人及你
无人及你 2020-11-22 06:44

I\'m building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it coul

30条回答
  •  故里飘歌
    2020-11-22 07:44

    MbUnit got a nice wrapper for this called Reflector.

    Reflector dogReflector = new Reflector(new Dog());
    dogReflector.Invoke("DreamAbout", DogDream.Food);
    

    You can also set and get values from properties

    dogReflector.GetProperty("Age");
    

    Regarding the "test private" I agree that.. in the perfect world. there is no point in doing private unit tests. But in the real world you might end up wanting to write private tests instead of refactoring code.

提交回复
热议问题