Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is useless to do unit test after writing code?

Tags:

unit-testing

I finished an app and after that I'm trying to write unit test to cover all methods.

The thing is that Im seeing that I'm testing my code with the knowledge of how it works.

For me is a bit stupid because I know how the code works and I'm testing what is my code actually doing.

My question is:

Is this useless? Im testing what it does, not what it is supposing to do. My code works but I can improve it. Then:

Should I complete all my tests and then try to refactor my code changing my test to "How the code should work" and making the changes to the app to pass the test?

Thank you.

like image 963
Jesus Rodriguez Avatar asked Dec 19 '10 14:12

Jesus Rodriguez


1 Answers

You need to test "How the code should work". That is, you have a clear idea of what a particular method should behave like, then create the set of tests that covers that behaviour. If your code fails the test then you can fix it.

Even though your code is working now you still need the tests for regression testing. Later when you modify your code or add new extensions to it you need to ensure that you did not break the existing functionality. The set of tests that you derive today will be able to tell you how well you did.

like image 171
Vincent Ramdhanie Avatar answered Sep 20 '22 01:09

Vincent Ramdhanie