官术网_书友最值得收藏!

Benefits and pitfalls

We have seen how easy it is to create test cases, run them, and analyze the report. Every framework has some benefits and pitfalls. In this section, we will look at some generic benefits and pitfalls.

Benefits of unit testing

The following are a few benefits of using unit testing for our projects:

  • Quickly making big changes: We can make big changes easily if we have included unit tests in system. As we know, it works properly because we have run the tests, we simply need to make sure that its working now by just running test again.
  • Boost your confidence: Unit testing helps you to boost up your confidence about requirements completion. It helps you to make a decision about when you can stop coding. Tests give you confidence that you have performed enough coding for one requirement and now we can move to other requirements. If unit tests are written properly and run every time when we carry out minor changes, then we can easily catch any bugs introduced due to change.
  • Helps to understand system design: Unit tests help you to understand system design and code written by developers. Instead of spending time to understand code, you can focus on outlining conditions and boundaries for the code and output that we expect from that. Good unit tests can help document and define what something is supposed to do.
  • Green lighting development: When we see green light at a traffic signal, the same feeling we get once we see successful output from any unit test. Likewise, we can even get the point from where we left by seeing the next red signal on the way which needs fixing. This way, we can easily get feedback for our code and visual effect for the same.
  • Faster development: Some people have a belief that writing unit tests double the effort to complete any development or take more time to complete any module, but unlikely that belief is not right. Writing unit test is relatively less tough and takes less effort and save more time in completing the development for any system. One can realize this by including unit test in their system.
  • Easy debugging: Let's say we wrote some code, there are some errors reported and we need to fix them. We will check in my browser for the issue, using a developer tool like Firebug. We will try to check for JavaScript errors via console log. After understanding the issue, we will make some changes, go back to browser, reload the page, and check if the error still exists. We would even need to make some changes to DOM via command line or debug via script tab. But if we had unit tests, we would have run the tests and see all the issues at once. One more advantage can be considered in case of unit test is whenever any test fails; only latest changes need to be checked/debugged. We don't need to check the whole module again.
  • Reusable code: In order to write unit test for any system, we need to make code modular. This simply means that we can easily reuse and understand that code in near future. This way, we increase production of reusable code in the system.
  • Saving cost: By writing a unit test, we will save cost for any system as we will find more defects in the development phase in comparison to acceptance testing phase or go live phase. That way we are saving time, effort, and cost.

Pitfalls of unit testing

We have seen different benefits of unit testing; now let's see what kind of pitfalls can occur during unit testing implementation:

  • Wrong assumptions for unit testing: Unit testing is not a tool, it's a methodology or technique. We need a set of acquired skills to understand that methodology. Sometimes, we do correct coding, but with wrong assumptions and it can happen that we end up writing wrong unit test. This can happen to anybody. It needs proper training and experience. Before writing any unit test, it is necessary that we understand the method of writing unit test. Only then we implement that in our system.
  • Not suitable when under tight deadlines: Many times it happens that deadlines for development are very tight or strict. In that case, it will be difficult for any developer to allot proper time for writing unit test. It is normally the job of the whole organization to understand the importance of unit test and give proper timing to develop good quality unit test.
主站蜘蛛池模板: 赣榆县| 衡水市| 汉阴县| 洱源县| 称多县| 惠水县| 垫江县| 壤塘县| 海伦市| 长沙县| 隆德县| 台南县| 宝丰县| 普宁市| 五指山市| 南雄市| 明溪县| 临泉县| 庆安县| 明水县| 石狮市| 汕头市| 康乐县| 河曲县| 安远县| 屯昌县| 丽江市| 普兰店市| 新丰县| 卓尼县| 南郑县| 河北省| 铁岭市| 六安市| 安新县| 如东县| 浮梁县| 龙江县| 乐业县| 津市市| 湛江市|