Self-Defense as a legal concept dates to Roman Law, which serves as a core of most Western Law. Common Law and Civil Law and Article 12 of the Universal Declaration of Human Rights all affirm the right to self-defense and the use of reasonable force in the defense of one's self and others and one's property.
In the United States, where this scenario could occur (1 out of 38 gun deaths in the United States is justified, i.e. Self-Defense. As the Reasonable force standard means that aiming a gun at another person in self-defense (ordinarily an assault charge), gun use in self-defense is thought to be much higher than this number).
Self-Defense is what is known as an Affirmative Defense. The difference between an ordinary legal defense and an Affirmative Defense is that Affirmative Defense will cede that the actions that the defendant was charged with were done by the defense (In this case, Bob admits that he shot Rob and Rob did die from that bullet BUUUUUUUUT Rob was trying to rob Bob and so Bob shot Rob to prevent himself from becoming a victim of Rob's robbery of Bob's property. (Sorry for that bad pun, but you set me up to make it)).
Because Bob admits to killing Rob he has just admitted to homicide... but if he can proves that it was justified homicide (per self-defense right) as opposed to unjustified homicide (illegal per statue or case law, depending on jurisdiction). At this point, the burden of proof shifts from the Prosecution to the Defense and Bob must now prove that, despite the fact he willfully admits to committing a homicide, but that in this particular case, Bob was acting within his rights. This means that Bob has waived his right to self-incrimination as the nature of his defense is self-incriminating.
To Long Didn't Read (with cookies!):
Innocent until Proven Guilty/Right agaisnt Self-Incrimination:
Prosecution: Bob took the cookies from the cookie jar.
Bob: Not me, couldn't be? (Prove it!/I'm innocent and that's all I'm saying to you about that.)
Prosecution: Then Who? (aka "I have an eyewitness who said they saw you")
Bob: Dick took the cookies from the cookie jar (aka Impeaching the witness/evidence, negation of evidence on account that some other Dick stole the cookies raising reasonable doubt.).
Prosecution: Bob stole the cookies from the cookie jar.
Bob: Yeah, but Rob said he would kill my girlfriend if I didn't. Here's my girlfriend Alice to testify to what I said and the location as to where she was held in Canada when Rob caught her while visiting her folks (Everyone knows Canadian girlfriends can be part of elaborate lies, but the story checks out, providing reasonable doubt to the crime, even though Bob admits to taking the actions he was accused of. By the by, this is Duress, not Self-Defense... there are some different things, but for legal rights of the Defendant, they don't matter here.).
Okay, now that we are out of the woods, the implication made by Bob not testifying to avoid self incrimination is that, Bob may have been party to something else that is illegal that was the reason Rob tried to attack Bob while Bob was engaged in that activity. Generally, if you were attacked while engaged in a crime, self-defense does not apply... you cannot shoot someone for coming at you while you're mugging a third party and claim your aggressor was killed in your own self defense. However, lets say that Bob is happening down his way and sees Rob robbing Roberta, a woman who is an illegal immigrant. Bob acts in defense of Roberta, and kills Rob, but if he admits to this part of the story, Roberta could be deported, which he does not want to do. If he says she is his witness, she gets the attention of law-enforcement and could be deported. Or Bob was follow Roberta (this time a legal citizen) with intent to rob her... but then he sees Rob in the distance attack Roberta and proceed to rape her... Bob may be a mugger, but he's no monster and shoots Rob to save Roberta. If he testifies to this, he will have to admit to a crime.
In these cases, Bob should DEFINATELY tell his lawyer the full story as attorney client privlege means the his lawyer cannot disclose anything Bob says (with few exceptions) to anyone and can advise Bob of the best course of action (though Bob can insist that he does not want to do this). In both situations typically this would mean that Bob and his attorney would work out a deal with the prosecution (in the United States at least. Plea bargains are frowned upon in most other districts, though not always illegal to make). In the both scenarios, he need not explain why he is there, so long as he is legally within his right to be there, however, having Roberta as a witness is vitally important to him as it can confirm his story. He need not prove beyond a shadow of a reasonable doubt an Affirmative Defense, but he needs to show some proof it could have happened. In the later story, it may still be in his interest as generally, Statements against one's own interest (i.e. I was going to do a crime, when I heard someone discussing plans to do a way worse crime.) are generally more credible penitentiary statements because admitting to possible crime is not something you would want to do.
While it's unlikely that Bob's lawyer wouldn't advise him to not testify, Bob may still have bullheaded reason to believe he shouldn't and his lawyer would have to respect that choice of Bob's.