Sayyiduna Zayd bin Khalid al-Juhani (may Allah be pleased with him) says that the Messenger of Allah (peace and blessings be upon him) said: "Shall I not tell you of the best of witnesses? Those who give their testimony before they are asked."
(b) This refers to the person who holds a testimony while the person (concerned) does not know of it.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الشهادات / 20594
Amr bin Dinar narrates from Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) that whoever holds a testimony should not say: I will testify to it only before an imam (ruler); rather, he should testify, so that perhaps he will turn back or desist.
This is mawquf (a Companion's statement), and that is what is correct; it has also been narrated as marfu' (from the Prophet), but its attribution to the Prophet is not authentic.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الشهادات / 20596
Muhammad bin Ubaydullah al-Thaqafi says that Sayyiduna Umar bin al-Khattab (may Allah be pleased with him) wrote: Whoever holds a testimony and does not give it when he saw (the event) or when he came to know of it, is only testifying (later) out of rancour.
This is munqati' (broken) between al-Thaqafi and Umar (may Allah be pleased with him).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الشهادات / 20597