How to JUnit Test a Private Method

2010, October 31

I was recently writing a cache for MP3s at work, and I needed to test some private methods. Testing a private method in Java is doable using reflection.

Look, in that class, there’s a private method. Let’s test it using the code below.

Testing private methods is achievable using reflection. Marvellous.