Because you would have to manually test every single possible outcome of your program. With tests this will be done automatically :)
For large systems a small change in a model can break things your weren't even working on.
I wonder why would you write laravel test code when you can actually check the result directly on the program?
Because you would have to manually test every single possible outcome of your program. With tests this will be done automatically :)
For large systems a small change in a model can break things your weren't even working on.
Can I use the same test program if I have a small change on the model for example to see which part show errors after the model changes?
Hi @davy_yg there are a lot lot of reasons.
It is fastest to test, while you can test with a refresh button, once you have two test done, with a single shortcut you can test both tests, now imagine your entire application with 15 types of resources, and several different states of each one within 5 minutes, and do it on every deploy or as you wish. Thats why people say tests are awesome but you just notice it after the second run.
When you test your app, as a developer we tend to test only the happy path, if its a form and you test that it will save you will skip that each field is required. With test driven development, each feature will be a test and will stay there. So you try in advance to check different routes of your code.
You could integrate those test in an automatic tool before deploying, so it will not be deployed if something failed by your team or even yourself.
Tests helps you to think easily about a feature caring only about the input and output, once done you care in the code that will meet the criteria that you thought before, it will help you to code and think more consistently.
Refactors, it is a common phrase to say "if its working, don't touch it" but that's when you think that a feature was hard and it will be harder to adapt to some edge cases or new actions, if you do a test, you could do the feature however you want, and later if your response is slow, or needs more logic, or extract a part of the code to a method to use it in another place, you do that and then run the test and you will have re-utilizable code and tested to use it in another place.
There are a lot of other reasons but those are the ones of what I think are the best ones.
You could do several types and levels of tests, you could test the UI, endpoints or objects, or combine them however you want. I recommend you to start with something easy like a happy path of an endpoint or a view.
You will learn how to tests more details once you do the easy ones
I thought when you write the test code you have write every single test code in order not to keep part of the tests if you forget to write it then it will not be tested. Is that not tedious?
Also, how can reuse the test code for different programming logic? So the test code is not reusable?
It's not about being reusable necessarily... Yes it is tedious.
But imagine this:
After EVERYTHING you change you click every single link on your page to see if it still works. Fill out every single form and submit it and so on.
Do that five times and you will happily write a test that does that all for you automatically at the push of a button :)
Yes you could reuse the test code you use more often like creating an object with pre-requisites, but the tests are the simplest code your application will have because it will not contain or should not contain difficult logic just inputs and assertions. So, yes at the beginning it is tedious but later you will do it as any thing you do automatically in your life.
Please or to participate in this conversation.