There is a custom that each pope writes a spiritual testament to be made public only after his death. The Vatican published the Spiritual Testament of Benedict XVI, which was written on 29 August 2006.
Here is the translated version of the Spiritual Testament translated by CNA:
My Spiritual Testament
If in this late hour of my life I look back at the decades I have been through, first I see how many reasons I have to give thanks. First and foremost I thank God himself, the giver of every good gift, who gave me life and guided me through various confusing times; always picking me up whenever I began to slip and always giving me again the light of his face. In retrospect I see and understand that even the dark and tiring stretches of this journey were for my salvation and that it was in them that He guided me well.
I thank my parents, who gave me life in a difficult time and who, at the cost of great sacrifice, with their love prepared for me a magnificent abode that, like clear light, illuminates all my days to this day. My father’s lucid faith taught us, children, to believe, and as a signpost it has always been steadfast in the midst of all my scientific acquisitions; the profound devotion and great goodness of my mother represent a legacy for which I can never give thanks enough. My sister has assisted me for decades selflessly and with affectionate care; my brother, with the lucidity of his judgments, his vigorous resolve and serenity of heart, has always paved the way for me; without this constant preceding and accompanying me I could not have found the right path.
From my heart I thank God for the many friends, men and women, whom He has always placed at my side; for the collaborators in all the stages of my journey; for the teachers and students He has given me. I gratefully entrust them all to His goodness. And I want to thank the Lord for my beautiful homeland in the foothills of the Bavarian Alps, in which I have always seen the splendor of the Creator Himself shining through. I thank the people of my homeland because in them I have been able again and again to experience the beauty of faith. I pray that our land remains a land of faith, and I beg you, dear countrymen: Do not let yourselves be turned away from the faith. And finally I thank God for all the beauty I have been able to experience at all the phases of my journey, especially, however, in Rome and in Italy, which has become my second homeland.
To all those whom I have wronged in any way, I heartily ask for forgiveness.
What I said before to my countrymen, I now say to all those in the Church who have been entrusted to my service: Stand firm in the faith! Do not let yourselves be confused! It often seems that science — the natural sciences on the one hand and historical research (especially exegesis of Sacred Scripture) on the other — are able to offer irrefutable results at odds with the Catholic faith. I have experienced the transformations of the natural sciences since long ago and have been able to see how, on the contrary, apparent certainties against the faith have vanished, proving to be not science, but philosophical interpretations only apparently pertaining to science; just as, on the other hand, it is in dialogue with the natural sciences that faith, too, has learned to understand better the limit of the scope of its claims, and thus its specificity. It is now sixty years that I have been accompanying the journey of Theology, particularly of the Biblical Sciences, and with the succession of different generations I have seen theses that seemed unshakable collapse, proving to be mere hypotheses: the liberal generation (Harnack, Jülicher etc.), the existentialist generation (Bultmann etc.), the Marxist generation. I saw and see how out of the tangle of assumptions the reasonableness of faith emerged and emerges again. Jesus Christ is truly the way, the truth and the life — and the Church, with all its insufficiencies, is truly His body.
Finally, I humbly ask: Pray for me, so that the Lord, despite all my sins and insufficiencies, welcomes me into the eternal dwellings. To all those entrusted to me, day by day, my heartfelt prayer goes out.