Maybe you didn't impress them so they picked out someone else who did. It could have been they thought you would not be a good fit at the job or you didn't have enough experience . Interviewers go by their feelings sometimes and maybe they thought you wouldn't fit in with the people already working there. Being interviewed for a job does not guarantee you the job as you just found out. Kind of think back on your interview and work on your weak points for your next interview.
Happens to all of us Hun, all perfectly normal. Don't worry about it.
Tests generally are the "minimum standard" you need to achieve to work in that organisation. Just passing the test frequently isn't enough - because there's a lot of competition out there and you want to shine and impress.
Happens to me, all the time. -_-
There are some great books out there on interviewing... and even on-line. If you'll do some homework there, you'll recognize the error of your ways and learn what to say/do and what not to say/do. But sometimes? There's just a better candidate ahead of you.