I know that Lord Shiva tests his devotees' devotion towards him, but I would like to know the references in any Hindu texts that confirm this.
Yes, there are various events in our scriptures. But it doesn't mean that Lord Shiva will test for each and every devotee necessarily.
1) Testing of Upamanyu:
One of the popular events is when Lord Shiva took the form of Lord Indra and tested Upamanyu. That form of Lord Shiva is known as Sureshwara. Mahabharata in this chapter describes the event:
In this way, I adored Mahadeva for a full thousand years of the celestials. After this, the puissant Mahadeva, the Master of all the universe, became gratified with me. Desirous of ascertaining whether I was solely devoted to him and him alone, he appeared before me in the form of Sakra (Indra) surrounded by all the deities. As the celebrated Sakra, he had a thousand eyes on his person and was armed with the thunderbolt. And he rode on an elephant whose complexion was of the purest white, with eyes red, ears folded, the temporal juice trickling down his cheeks, with trunk contracted, terrible to look at, and endued with four tusks.
Lord Shiva (in the form of Indra) then tells Upamanyu as:
Addressing me, he said,--O foremost of regenerate persons, I have been gratified with thee. Beg of me whatever boon thou desirest,--Hearing these words of Sakra I did not become glad. Verily, O Krishna, I answered the chief of the celestials in these words.--I do not desire any boon at thy hands, or from the hands of any other deity. O amiable deity, I tell thee truly, that it is Mahadeva only from whom I have boons to ask. True, true it is, O Sakra, true are these words that I say unto thee. No other words are at all agreeable to me save those which relate to Maheswara....
Finally being satisfied with answers given by Upamanyu, Lord Shiva shows up in magnificent form:
Having said these words unto the chief of the celestials, I became overwhelmed with grief at the thought of Mahadeva not having been gratified with me not withstanding my severe austerities. Within the twinkling of an eye, however, I saw the celestial elephant I had beheld before me transformed into a bull as white as a swan, or the Jasminum pubescens, or a stalk of the lotus or silver, or the ocean of milk. Of huge body, the hair of its tail was black and the hue of its eyes was tawny like that of honey. Its horns were hard as adamant and had the colour of gold. With their very sharp ends, whose hue was a mild red, the bull seemed to tear the Earth. The animal was adorned all over with ornaments made of the purest gold. Its face and hoofs and nose and ears were exceedingly beautiful and its waist too exceedingly well-formed. Its flanks were possessed of great beauty and its neck was very thick. Its whole form was exceedingly agreeable and beautiful to look at. Its hump shone with great beauty and seemed to occupy the whole of its shoulder-joint. And it looked like the summit of a mountain of snow or like a cliff of white clouds in the sky. Upon the back of that animal I beheld seated the illustrious Mahadeva with his spouse Uma.
SatRudra Samhita chapter 32 of the Shiva Purana also describes this story on how Lord Shiva took form of Indra and tested Upamanu:
एतस्मिन्नन्तरे शंभुर्विष्ण्वाद्यैः प्रार्थितः प्रभुः ।। परीक्षितुं च तद्भक्तिं शक्ररूपोऽभवत्तदा।।१९।। शिवा शचीस्वरूपाभूद्गणाः सर्वेऽभवन्सुराः।। ऐरावतगजो नन्दी सर्वमेव च तन्मयम् ।।3.32.२०।।। ततः साम्बः शिवः शक्रस्वरूपस्सगणो द्रुतम्।। जगामानुग्रहं कर्तुमुपमन्योस्तदाश्रमम् ।। परीक्षितुं च तद्भक्तिं शक्ररूपधरो हरः ।। प्राह गंभीरया वाचा बालकन्तं मुनीश्वर ।। २२।।
In the meantime, requested by Vishnu and others, Shiva assumed the form of Indra in order to test his devotion. Parvati took the form of Sachi. The Ganas became the gods, Nandin became the elephant Airavata. Everything belonging to Shiva became that of Indra. Then Shiva accompanied by Parvati and the Ganas, and assuming the form of Indra went to the hermitage of Upamanyu in order to bless him. O great sage, in order to test his devotion, Siva in the form of Indra, spoke to the boy in a grave tone.
2) Testing of Parvati:
Parvati is always present as the left part in the body of Shiva, though while in her form as the daughter of mountains she did a severe penance using Panchakshari mantra taking initiation from Narada Rishi. Lord Shiva first sends Saptarishis to test the devotion of Parvati and when they return Lord Shiva himself goes to Parvati taking the form of Jatila and begins to criticize Shiva. Rudra Samhita chapter 26 and chapter 27 of Shiva Purana deals with this story:
गतेषु तेषु मुनिषु स्वं लोकं शंकरः स्वयम् ।। परीक्षितुं तपो देव्या ऐच्छत्सूतिकरः प्रभुः ।।१।। परीक्षा छद्मना शंभुर्द्रष्टुं तां तुष्टमानसः।। जाटिलं रूपमास्थाय स ययौ पार्वतीवनम् ।। २ ।। अतीव स्थविरो विप्रदेहधारी स्वतेजसा ।। प्रज्वलन्मनसा हृष्टो दंडी छत्री बभूव सः ।। ३ ।।
When those sages returned to their abodes, lord Shiva, the cause of great enjoyment and protection wanted to test the penance of the goddess. Under the pretext of testing, Shiva wanted to see her. With a delighted mind He assumed the form of a Jatila (an ascetic with matted hair) and went to the forest of penance of Parvati. He took the form of a very old man with the body of a brahmin. His brilliance shone. He was delighted in mind. He had an umbrella and a staff.
He begins to heavily criticise Lord Shiva and starts saying things like:
तन्मध्ये हि विरूपाक्षे एकोपि न गुणः स्मृतः ।। ३२ ।। तवापि कामो दयितो दग्धस्तेन हरेण च ।। अनादरस्तदा दृष्टो हित्वा त्वामन्यतो गतः ।।३३।। जातिर्न दृश्यते तस्य विद्याज्ञानं तथैव च ।। सहायाश्च पिशाचा हि विषं कण्ठे हि दृश्यते ।। ३४ ।। एकाकी च सदा नित्यं विरागी च विशेषतः ।। तस्मात्त्वं हि हरे नैव मनो योक्तुं तु चार्हसि ।। ३५ ।। क्व च हारस्त्वदीयो वै क्व च तन्मुण्डमालिका ।। अंगरागः क्व ते दिव्यः चिताभस्म क्व तत्तनौ ।। ३६ ।। सर्वं विरुद्धं रूपादि तव देवि हरस्य च ।। मह्यं न रोचते ह्येतद्यदिच्छसि तथा कुरु ।।३७।। असद्वस्तु च यत्किंचित् तत्सर्वं स्वयमीहसे ।। निर्वर्तय मनस्तस्मान्नोचेदिच्छसि तत्कुरु ।। ३८ ।।
There is not even a single quality in the odd-eyed Siva out of the innumberable qualities pleasing to women and expected in bride-grooms.Your friend Kama was burnt by Shiva. He insulted you also by leaving you off and going elsewhere. His caste is not recognised. He has no learning or wisdom. His assistants are the ghosts. Poison is seen even in His throat. He also moves about in isolation. He is detached from everything particularly. Hence you cannot fix your mind in Him. Where your necklace and where the garland of skulls that he wears? Where your rich divine unguent and where the ash from the funeral pyre that He has on His body? O divine lady, everything concerning you and Siva, such as form, features etc. is mutually discordant. I do not like your resolution. You can do whatever you please.You yourself have evolved taste for all bad objects. Turn your mind from Him. If not, do whatever you please.
Lord Shiva then finally shows his true form to Devi Parvati:
इत्युक्त्वा चोमया यावत्पादमुत्क्षिप्यते मुने ।। असौ तावच्छिवस्साक्षादालंबे प्रियया स्वयम् ।। ४१ ।। कृत्वा स्वरूपं सुभगं शिवाध्यानं यथा तथा ।। दर्शयित्वा शिवायै तामुवाचावाङ्मुखीं शिवः ।।४२।। शिव उवाच ।। कुत्र यास्यसि मां हित्वा न त्वं त्याज्या मया पुनः ।। प्रसन्नोऽस्मि वरं ब्रूहि नादेयम्विद्यते तव ।। ।। ४३ ।। अद्यप्रभृति ते दासस्तपोभिः क्रीत एव ते ।। क्रीतोऽस्मि तवसौन्दर्यात्क्षणमेकं युगाय ते ।। ४४ ।। त्यज्यतां च त्वया लज्जा मम पत्नी सनातनी ।। गिरिजे त्वं हि सद्बुध्या विचारय महेश्वरि ।। ४५ ।। मया परीक्षितासि त्वं बहुधा दृढमानसे ।। तत्क्षमस्वापराधम्मे लोकलीलानुसारिणः ।। ४६ ।। न त्वादृशीम्प्रणयिनीं पश्यामि च त्रिलोकके ।। सर्वथाहं तवाधीनस्स्वकामः पूर्य्यतां शिवे ।। ४७ ।।
Saying this, O sage, even as Parvati was about to step ahead, the brahmin manifesting as Shiva clasped his beloved. After assuming the handsome form in the manner Parvati had meditated upon and manifesting it to Parvati, Shiva addressed her while she stood with her lowered head. Shiva said:-- "Where will you go, leaving me? You are not to be discarded again by me. I am delighted. Tell me what boon shall I grant you. There is nothing that cannot be given to you. From today I am your slave bought by you by performing penance. I have been bought by your beauty. Even a moment appears like a Yuga. O Parvati, O great Goddess, you are my eternal wife. Let this shyness be eschewed. You please ponder with your keen intellect. O steady-minded one, you have been tested by me in various ways. Let my guilt be excused in following this worldly game. Even in the three worlds I do not see a beloved like you. O Parvati, in every respect I am subservient to you. You can fulfil all your desires.
3) Testing of Arjuna:
This chapter of Mahabharata describes how Lord Shiva tested Arjuna by taking a form of Kirata and also fought with him for sometime:
Vaisampayana said, "After all those illustrious ascetics had gone away, that wielder of the Pinaka and cleanser of all sins--the illustrious Hara--assuming the form of a Kirata resplendent as a golden tree, and with a huge and stalwart form like a second Meru, and taking up a hand some bow and a number of arrows resembling snakes of virulent poison, and looking like an embodiment of fire, came quickly down on the breast of Himavat. And the handsome god of gods was accompanied by Uma in the guise of a Kirata woman, and also by a swarm of merry spirits of various forms and attire, and by thousands of women in the form and attire of Kiratas. And, O king, that region suddenly blazed up in beauty, in consequence of the arrival of the god of gods in such company. And soon enough a solemn stillness pervaded the place. The sounds of springs, and water-courses, and of birds suddenly ceased. And as the god of gods approached Pritha's son of blameless deeds, he beheld a wonderful sight, even that of a Danava named Muka, seeking, in the form of a boar, to slay Arjuna.
Kirata form of Lord Shiva and Arjuna heavily fight for some time:
The illustrious god in the form of the huge-bodied Kirata, however, bore that shower of trees and rocks with patience. The mighty son of Pritha then, his mouth smoking with wrath, struck the invincible god in the form of a Kirata, with hi clenched fists, blows that descended like thunderbolts. The god in the Kirata form returned Phalguna's blows with fierce blows resembling the thunderbolts of Indra. And in consequence of that conflict of blows between the son of Pandu and the Kirata, there arose in that place loud and frightful sounds. That terrible conflict of blows, resembling the conflict of yore between Vritra and Vasava, lasted but for a moment.
Arjuna recognizes that the Kirata is Lord Shiva himself after this incident:
And struck by the illustrious god, he became breathless and, falling down on earth without power of moving, looked like one that was dead. Soon, however, he regained consciousness, and, rising from his prostrate position, with body covered with blood, became filled with grief. Mentally prostrating himself before the gracious god of gods, and making a clay image of that deity, he worshipped it, with offerings of floral garlands. Beholding, however, the garland that he had offered to the clay image of Bhava, decking the crown of the Kirata, that best of Pandu's sons became filled with joy and regained his ease. And he prostrated himself thereupon at the feet of Bhava, and the god also was pleased with him.
Then Lord Shiva gives him darshana in his real form:
Vaisampayana continued, "Phalguna then beheld him--Mahadeva--that god of blazing splendour-that wielder of the Pinaka-that one who had his abode on the mountains (of Kailasa)--accompanied by Uma. Bending down on his knee and bowing with his head, that conqueror of hostile cities-the son of Pritha-worshipped Hara and inclined him to grace. And Arjuna said, 'O Kapardin, O chief of all gods, O destroyer of the eyes of Bhaga, O god of gods, O Mahadeva, O thou of blue throat, O thou of matted locks, I know thee as the Cause of all causes. O thou of three eyes, O lord of all!
This testing of Arjuna by taking form of Kirata is also described in Shiva Purana Shatrudra Samhita chapter 39:
विचार्य्येति च तत्रैव बाणं संस्थाय संस्थितः ।।२४।। एतस्मिन्नन्तरे तत्र रक्षार्थं ह्यर्जुनस्य वै ।। तद्भक्तेश्च परीक्षार्थं शंकरो भक्तवत्सलः।।२५।। विदग्धभिल्लरूपं हि गणैः सार्ध महाद्भुतम् ।। तस्य दैत्यस्य नाशार्थं द्रुतं कृत्वा समागतः ।। २६ ।।
In the meantime, Shiva, favourably disposed to his devotees, assumed the wonderful form of an efficient hunter and came there along with his Gaṇas in order to slay that Daitya, to protect Arjuna as well as to test his devotion. The hunter had tucked up his lion-cloth and folded up Shiva’s banner. His body was lined with the white ash. He held a bow and arrows.
There are many other stories like Lord Shiva taking the form of Yatinatha to test Bhilla couples, Lord Shiva hiding a lotus flower from Lord Vishnu, Lord Shiva taking the form of Yaksha to test gods, etc... I might add these stories later in this answer also. But for now, I think the above stories are sufficient!