I am testing a class that looks like the example below, using JunitTesting.
public RandomObject MainMethod(int id) {
RandomObject o = dBconn.getRandomObject(id);
subMethod(o);
//also calling other private methods here
return o;
}
private subMethod(RandomObject o) {
//Do something random here
}
I have three choices:
- Only test my MainMethod(), but then I must access DB by hardcoding DB-values into my test.
- I can avoid testing MainMethod() and only test the subMethod, but then I must make my private methods public.
- Do both 1 and 2.
What is best practice?