Tag Archives: testing

Using PowerMock to mock a call to super

Let’s say you are wanting to test UberEmployee below: [java] public class Employee { public int calculatePay() { return someComplexCalculations; } } public class UberEmployee { public static final long UBER_BONUS = 1000; @Override public int calculatePay() { return super.calculatePay() + 1000; } } [/java] Perhaps you can’t change Employee but you still want to… Read More »

Unit testing private methods using reflection (and other solutions)

When it comes to unit testing you might find yourself wanting to test private methods. Here’s four solutions, some much better than others. 1. Don’t test private methods (refactor!) If you find yourself needing to test private methods, you’re code is trying to tell you something – listen up! Unit tests should test the behavior… Read More »