When a teacher tests a student and then rewards or punishes the student, he does that, so that the student learns stuff he needs in his further life.
When someone does not pass God's test and ends in hell, what is the purpose of that punishment? The poor sinner has no chance to correct the errors he has made, since hell is eternal and you don't get a second chane.
So, why would God punish people with hell?
The student can use what he has learned during school in his later life. But where can you use what you have learned during the test of life?
I love using the teacher and student thought experiment. It's probably the first thing you think of when you think of the word "test" especially if your a student or teacher yourself.
If it was possible that the teacher could somehow zap into the brain of the student, everything that the student needs to know to go on to do what he/she wants to do, then there would be no need for a test. However, because the teacher cannot do that, there is a need for testing. But with Allah, everything is supposed to be possible, except for perhaps the illogical/inconceivable. But what is illogical/inconceivable about Allah putting the knowledge in our brains for what we need to do what we need to do in later life? After all, he put the knowledge into Muhammad's mind of the revelation.
We also need to ask, why do we need to know certain things in order to be what we want to be later on in life? It is because the world is of finite resources. What does that mean? It means that when you apply for a job, the boss will not accept all his/her applicants, simply because he/she cannot. The boss has limited wealth in order to pay the wages of his/her workers. Also, the boss only needs a finite number of tasks doing in his business, so too many workers would be unnecessary. Why does the boss only need a finite number of tasks doing? It is because the boss can only afford a finite amount of raw resources in order for his/her workers to work on. I can follow this further, but the general principle is that we are limited in everything. That is the need for testing. But what need is there for God to test? He has unlimited wealth, so he could afford to let an inifinite amount of people into heaven. Even if were thinking about spiritual wealth. Human's potential to have spiritual wealth is hindered by the nature that humans were given. But that human nature was created for us by God. God creates spiritual wealth, too. Heaven is infinite in resources too, so it is not that God cannot fit everybody into heaven. What need does God have to test us?