Portia's father devised the casket test as a way of weeding out the gold-diggers and time-wasters. He knew that once his wealthy, beautiful daughter came of age that numerous men would beat a path to her door, seeking her hand in marriage. But he wanted to make sure that the right man would marry his daughter, hence the casket test. There are three caskets in all—gold, silver, and lead, each one with a little inscription on the outside. Once each suitor has chosen a casket, he's to open it up to see if he's made the right choice. Inside the correct casket will be a portrait of Portia.
The Prince of Morocco is the first of Portia's suitors to try his luck. After hesitating for what seems like an eternity, he finally plumps for the gold casket, because he cannot believe that Portia's father would put the portrait of his beloved daughter in a casket made out of anything else. Unfortunately for him, when he opens the casket, he discovers, to his profound disappointment, that there's nothing inside but a skull with a scroll in its eye. On the scroll is written the message "All that glistens is not gold..." The Prince has made the wrong choice, and so he quickly exits.
The Prince of Arragon is next up. He chooses the silver casket, because it bears the inscription "Who chooseth me shall get as much as he deserves." As the Prince thinks that he deserves Portia, he opens up the casket, expecting to see her portrait inside. But it isn't there. Instead, he finds the portrait of a fool. Outraged at being made to look like a complete idiot, the Prince protests before hastily departing with his entourage.
Finally, Bassanio gets his turn. Thanks to a little bit of help from Portia, he opts for the lead casket. He hasn't chosen the casket on the basis of its outward appearance. This reflects his true feelings for Portia; he loves her for herself and not for her money. When he opens up the casket Bassanio is overjoyed to see Portia's portrait and a scroll which says "Turn you where your lady is / And claim her with a loving kiss." Which he gladly does.