0

I am new to unit testing and i don't know how to test a private method?

Is there is any way to test a private method ?

I am using MSTest framework.

Private Method Code:

private int IncreasePoints(int userPoints)
{
   if (userPoints > 0 && userPoints < 50)
      userPoints += 0;

   else if (userPoints >= 50 && userPoints < 100)        
      userPoints += 10;

   else if (userPoints == 100)
      userPoints += 15;

   else if (userPoints > 100)
      userPoints += 25;

   else
      userPoints += 0;

   return userPoints;
}
Rehan Shah
  • 1,505
  • 12
  • 28
  • 1
    check this : https://www.infragistics.com/community/blogs/b/dhananjay_kumar/posts/how-to-unit-test-private-methods-in-ms-test – Ehsan Sajjad Jan 06 '19 at 12:33
  • 5
    In short... Don't unit test private methods. Test the exposed functionality of an object. Unit tests are consuming code just like any other consuming code, they shouldn't know or care about the implementation details. And the more coupled they are to those details, the more brittle they are when those details change. If refactoring your class requires you to re-write your tests then that breaks the red-green-refactor cycle. – David Jan 06 '19 at 12:33
  • @EhsanSajjad Thanks.. https://www.infragistics.com/community/blogs/b/dhananjay_kumar/posts/how-to-unit-test-private-methods-in-ms-test Worked for me.... – Rehan Shah Jan 06 '19 at 12:39

0 Answers0