All posts
How to Test Private Methods?

How to Test Private Methods?

From time to time I have had to face this question: how to test private methods? I have put together in an article the techniques that I usually use.

blog-cover

This is a question that I have encountered with some frequency for a long time. So I thought I would put together my thoughts on the subject here.

Short answer

Never.

Long answer

Never ever.


What if…?

If you really want to test a private method, consider extracting that private method logic into a separate class, and write a unit test for that class’ behavior.

For this one, I was inspired by Fran Iglesias’ original post.

hjklmove /search yyank dtheme ilang ttoc mmark nnote ?help

Keyboard Shortcuts

Movement vim hjkl

hPrevious post← left
jScroll down↓ down
kScroll up↑ up
lNext post→ right
ggScroll to top
GScroll to bottom
nNext sectionnext heading
NPrevious sectionprevious heading

Go to g = go

ghHomego home
gbBloggo blog
grReadingsgo readings
gpTopicsgo topics
geServicesgo services
gaTalksgo talks

Actions

/Searchvim search
yYank URLvim yank
dToggle themedark mode
tToggle TOCtable of contents
iSwitch languagei18n
fFollow linkfollow link
mToggle highlightmark text

General

?Show this help
ShiftHold to show hints
EscClose
:Terminalvim command mode