Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write unit test for private method in c# using moq framework?

I want to write unit test for private method in C# using moq framework, I've search in StackOverFlow and Google, but I cannot find the expected result. Please help me if you can.

like image 824
PeaceInMind Avatar asked Aug 11 '14 07:08

PeaceInMind


1 Answers

You can't, at least not with Moq.

But more importantly, you shouldn't. First off, you don't test methods, you test behaviours. Second, in order to test behaviours, you exercise a type's public API and verify the outcomes of that exercise.

Private methods are implementation details. You don't want to verify how things get done, you want to verify that things do get done.

like image 94
dcastro Avatar answered Sep 19 '22 15:09

dcastro