What are unit tests and why should I care?

后端 未结 8 1439
礼貌的吻别
礼貌的吻别 2020-12-13 05:13

Okay, I develop web applications in PHP and JavaScript and a lot of times here on Stack Overflow I have seen the word unit test passing by, but nowhere on the websi

8条回答
  •  天涯浪人
    2020-12-13 05:42

    If you write an application of any description, you should consider unit tests. Done properly, they force you to think about the quality of code you are delivering to your users. I think the issue you have here, is the difference between unit testing code and automated unit testing. Unit testing can be done as simply as writing down a set of tests and then manually running through them.

    Automated unit testing, on the other hand, relies on you having some form of application/harness to run and rerun tests. With automated unit tests you can rerun tests just by pressing a button. So why is rerunning a test so important? Simply speaking, you don't write applications run tests on them once and then walk away from them. Write your tests so that you exercise your code in discrete little runs and run them throughout the development process. By doing this, with a well written set of tests, you stand a much better chance of identifying code that's been broken by upgrades.

提交回复
热议问题