Many times a case has multiple defendants. A crime will occur and several people will get arrested. Some might be friends or they might be strangers to each other. But, like most events in our lives, we do what we do with people we know.
So what happens when several people are prosecuted in the same case? All the defendants have their own lawyers because each defendant has his own point of view, his own measure of responsibility and his own interests in how the case comes out. Because of this, the defendants are often offered a chance to cut a deal with the District Attorney and get a lesser sentence in return for testimony against the other defendants.
Why would the District Attorney agree to make a deal with a defendant in a case? First of all, there may be a lack of evidence. In other words, the District Attorney can't prove the case without one of the defendant's help. Second, the District Attorney might see the case as one with different measures of responsibility such that it makes sense to give one or more of the defendants a deal because the defendant is a minor "player" in the case. Finally, if a case simply has too many defendants to efficiently prosecute in a timely manner one or more of the defendants could be allowed to testify against the remaining defendants. This eliminates one more roadblock to the District Attorney's case.
Every defendant has to decide whether or not to accept an offer to testify against his once upon a time friends. Testifying for the prosecution is a life defining moment. Turning your back on your fellow defendants and accepting the lesser sentence offered by the District Attorney can put one's family at risk, certainly puts the testifying co-defendant's life in jeopardy, and should mean no further involvement in future criminal conduct. It can be a life saver for the testifying co-defendant. To turn down a deal and refuse to testify for the prosecution is usually more than a defendant can resist.