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