salaam
subhanallah brother,
its both, its written and its a test,
this life in this dunaya is a test allah gave us, and allah says for every pain u get in this world u get a reward for( i dont hav a quote for this from the quran or sunnah, coz am at work, but inshallah someone will have it)...