Let's say I start developing a role game with characters that attack other characters and that kind of stuff.
Applying TDD, I make some test cases to test the logic inside Character.receiveAttack(Int)
method. Something like this:
@Test
fun healthIsReducedWhenCharacterIsAttacked() {
val c = Character(100) //arg is the health
c.receiveAttack(50) //arg is the suffered attack damage
assertThat(c.health, is(50));
}
Say I have 10 methods testing receiveAttack
method. Now, I add a method Character.attack(Character)
(that calls receiveAttack
method), and after some TDD cycles testing it, I make a decision: Character.receiveAttack(Int)
should be private
.
What happens with previous 10 test-cases? Should I delete them? Should I keep method public
(I don't think so)?
This question is not about how to test private methods but how to deal with them after a re-design when applying TDD
internal
or your language's equivalent to still prevent it being exposed. In fact Kevin Cline's answer is this kind of approach.