Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.48 KB

2023-10-20-how-to-test-private-methods.md

File metadata and controls

39 lines (26 loc) · 1.48 KB

+++ title = "How to test private methods?" description = "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." draft = false [taxonomies] tags = [ "testing", "software", "design" ] [extra] subtitle = "Testing private methods. When and how?" static_thumbnail = "/images/blog/2023-10-20/cover.jpg" +++

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.

Related posts

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