Consider it a great joy, my brothers, whenever you experience various trials, knowing that the testing of your faith produces endurance.
When I read passages like this, I think of persecution. Roman guards bursting into thatch-roofed homes and dragging off members of the underground churches. Being flogged, stoned, crucified for believing that Christ is the Messiah. That image that's less applicable and more "so far removed from me that it's on the other side of the world and 19 centuries ago." And maybe that is the image that James had in his mind, but I doubt he was referring only to that sort of trial.
Various trials. "I got a ticket on the way home." "I lost my job." "The man of my dreams found the woman of his... and it's not me." "My car won't start." "My sister isn't saved."
The testing of your faith. Your faith that God is still good, still sovereign, knows what He's doing, is doing exactly what's best for you.
Produces endurance. There's nothing you can endure for long that you could not endure for longer or better if you've endured it in the past and learned from it. A man who runs ten miles every day will do better in a marathon than a man who has never run a mile. If you've struggled to understand that "All things work together for the good of those who love Him," endured that frustration, and seen it prove itself true, you have that experience, that endurance, to recall when next a seemingly evil circumstance comes.
Consider it great joy. You have to love wisdom. You have to say, "I hate what has happened... but I love it because this pain is a gift, equipping me for other experiences and future conversations. God cares enough about me to teach me in ways that He knows will communicate to my weak mind." I want wisdom, so if I bear in mind that the unpleasant experiences God brings my way are going to give me that wisdom, are for my good, are for His glory, then they are deserving of a joyful reception.
It's just like exercise. A person who wants to look better and feel better and have more strength and balance will gladly endure the pain to get there. But like any good trainer will tell you,
"You have to want it."