Unit tests should be written before the code they are testing, so that you can see the test go from red (failing) to green (passing).
Unit tests should always fail first. To those without experience with test-driven development, this can often seem tedious or obvious: of course the test is useful, look, it passes! However, it is surprisingly easy to write a test that does nothing, or passes without changing the system under test.
All other tests can be written later. Integrating multiple components requires multiple working components; if you're going to write tests before you write code, then you by definition don't have all your components ready yet.