How to test private methods?

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.
Related posts
- Test-Driven (Development) What is challenging about it?
- Different beliefs about software quality Some thoughts about software quality
- The art of testing: where design meets quality From a software developer’s point of view
- The path to seniority in software How to become a Senior Software Developer?
For this one, I was inspired by Fran Iglesias’ original post.