In some agile methods like extreme programming, the test case for a method is written first. This is not a very efficient way to develop software. It is more efficient to write the code first and then write unit test cases for it after all the code for a class or group of classes for a component have been written.
One reason for this is because testing involves baggage. What this means is that if some test cases exist for a componenet and some significant changes need to be made to that component, then the test cases will have to be changed as well. This usually requires significant extra time and effort. If the test cases have not been written yet, then there is no baggage and no changes have to be made to test cases because they don’t exist yet.
There are some exceptions to this. For example, any code that involves using an outside interface that is hard to understand, has not been used before, is complex, or tricky then that code should be prototyped and tested before coding the component that uses that code. Solve the hard tricky parts first by encapsulating them into a class or function and writing test cases that prove they work as intended.
Another reason to code all the classes for a component is due to flow.