Yunus bin Ubayd narrates from al-Hasan (may Allah have mercy on him) that (this applies) in both cases: when he is called to bear witness, and when he is called to give his testimony.
Note: Others add from al-Hasan: For if all people refused to testify for one another, that would not be permissible for them.
A group of the Qur'an commentators held that this verse is about giving testimony, and the verse can bear both meanings, as al-Hasan held. In bearing witness it is a communal obligation (fard kifayah): when enough people undertake it, and the writing, those who stayed back are freed from sin; and Allah knows best.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الشهادات / 20601