Personally I use TDD, so I write my the tests first.
TDD is a little hard to understand at the beginning, so if you're new to the testing world I would advice you to start with BDD, i.e writing the code first.
Anyway, it doesn't really matter when you write the tests as long as they are good :)
I find personally I do my best when I write the tests first. For many years I was a test last developer and my tests where pretty bad.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.