How do you unit test private methods?

前端 未结 30 1908
无人及你
无人及你 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:24

    You could also declare it as public or internal (with InternalsVisibleToAttribute) while building in debug-Mode:

        /// 
        /// This Method is private.
        /// 
    #if DEBUG
        public
    #else
        private
    #endif
        static string MyPrivateMethod()
        {
            return "false";
        }
    

    It bloats the code, but it will be private in a release build.

提交回复
热议问题