Good student but terrible test taker? So I am gradute student in theoretical computer science. 

Throughout my education path up to highschool, I have all been praised a big lot by my teachers, some of them even went to such lengths as to say I was the most intelligent student they have ever taught. By dint of all that, I took it for granted that I must be cleverer than average and before I noticed, I might have gotten on a very high horse.

Then I got into college, and things started getting harder. The higher the horse, the bigger and harder the fall. So my grades stopped being close to full score, but not bad at all. Until I decided that I wanted to do a PhD later, and for that, I have to get very good marks and hope to get a scholarship.

Ever since, at the dawn of every test/exam, as opposed to the relaxed and cool mindset I'd be in before, I get very, very, VERY anxious and very flustered, either out of fear that I run out of time (because of a lived experience), or of not having the answer. That anxiousness would get lifted immeditely when time is up, and on my way back home, all answers or most of them, would start flowing in my head.

Only this morning, I had a test which I failed like never before. I quickly glossed over problems one by one in order, my mind would go blank for a few seconds, then I would deciddeto move on to the next problem and that it is no use wasting time on this one (because I wasn"'t going to find a solution), and that for every exercise. It is for a reason I say I failed today's like never before because I literally could do nothing; my mind was paralyzed and started weating and how I was going to not get to what I want to (PhD). But as soon as I got home and sat down for a few minutes, I solved prefectly 5 problems out 7  in 30 minutes (the test was to do within 90 minutes).

I was one of the most confident people in themselves before, but now I lost every bit of that confidence and wouldn't stop thinking I'm too dumb to make it. I have been struggling with this for two years now, and after today's huge blow, I decided to take to the internet and this board in order to try and find a solution. Chances are Academia is not the right board to ask this question in, but it must be the closest to that out of all other SE boards.

What can I do about my test taking so that my scores are more reflective of my natural ability?
I too went through a period where I panicked when taking tests. I saw a psychologist for help. Even if you choose not to go that route, you might find my experience helpful.

The problem began when I started taking the kind of tests where even the best students may not be able to answer all of the questions. I'd look at question one, not know how to answer it (at least, not right away), and begin to get nervous. Question two might seem daunting as well, so I'd become even more nervous. By the time I'd looked at question three, I was convinced that I would fail. Eventually I might realise that I knew how to do part of one of the questions. That gave me confidence to tackle another piece of another question, and so on. But I spent too much time panicking to do well on most tests.

The key for me in overcoming this was to realise that it was normal to not know how to answer any of the questions at first. I learned to expect it, but also to expect that after a couple of minutes I would begin to get ideas for solutions. By expecting that I would draw a blank at first, while realising that this wouldn't mean I'd fail the test, I kept myself from panicking.

Part of what the psychologist did was to help me understand this. The other thing was that he worked with me to visualise the test-taking procedure:
sitting down at the desk, turning over the paper, scanning the list of questions, not knowing how to answer any of them, then getting an idea, and so on. He talked me through the scenario while I did some relaxation exercises that he taught me.

Take comfort in the fact that your test-taking days are almost over. After you get a postgraduate degree, no one cares whether you passed with flying colours or barely squeaked by. Your publications will be far more important.