I know that it is recommended to write unit test before coding.
But my question is related to test cases.
When should I write test cases? When I already have written code or before it.
I know that it is recommended to write unit test before coding.
But my question is related to test cases.
When should I write test cases? When I already have written code or before it.
Welcome to SQA, TIKSN. Since your question distinguishes between unit tests and test cases, I assume you are asking about test cases written in English (or Armenian, or whatever) rather than automated tests.
You will hear a variety of opinions about this. Some people recommend writing the test cases before writing any code because the test cases help clarify details about the requirements. Other people recommend writing the test cases after the code is finished (or at least functionally complete) because the requirements (and therefore the test cases) are likely to evolve as the code is written.
The form of a written test case can vary from one person to the next, too. Some people prefer test cases with detailed, step-by-step instructions. Others prefer higher-level test cases that get the point across but stay out of the details. I prefer to write higher-level test cases before writing code. However, I also expect to revise my test cases as the code progresses.
Finally, it is interesting that you asked whether you should write the test cases. If you work with a tester, they may prefer to write the test cases for you, or at least collaborate with you on the test cases. There are several reasons why a tester might want to be involved; for example, if the tester knows about the test cases before the code is finished, they can plan for how much time and effort they will need to test your code.
Typically, you can do testing at any point in the development cycle; therefore you can write test cases at any point.
If you have requirements to build from, you have the building blocks for test cases in the future. If you have code, you can write test cases while the code is being built. If you already have the code, you can write tests too. Do you have data? You can write test cases. Do you have configurations? You can write test cases.
As per your request, "when should I write test cases?". It depends. It depends on:
At the end of the day, you need to take a look at your own risks and apply your own heuristics as to when your write test cases.
According to your question, you can write test cases after the partial completion of code because once the code is ready then you will be able to decide the expected result.
Once the expected result is known then it will help you a lot in writing test cases and to decide the Pass/Fail criteria. If more than 60 % code is completed then it will help you in identifying :