In this blog I want wrote about How I fix the unit test for bootstrap-slider project on GitHub.
Unit testing is a small piece of code written by the developer to verify that a small, well-defined function of the code under test is correct. In general, a unit test is used to determine the behavior of a particular function under a particular condition (or scene).
what I did to solve this problem is I tried to read line from line 149 to 162 very carefully, and try to understand what dose this test will do. Then I found this test is going to test the formatter option. The test value was given 9 and should be return 9 as well for passing this test. However, it always return 955 by the end. So the expect value is not match to real test function returned.
I tried to give different value to test the setValue() function but there are always 5 and 5 attached after the expected value that returned from getValue() fuction.
I try to debug it in the google chrome browser, then I found a very interesting result that this function actually return the correct value. As you can see the left side picture, I give setValue() function a number 9 and getValue() function is return a number 9.
I aware of this function is just works fine so should be another error cause this issue. I uncomment all of the unit test code exclude this one and it pass the unit test WOW!!! So, it demonstrate what I’m thought.
This is the problem!!! Is not located in problem line but in other unit test function.
The original unit test programmer doesn’t destory the silder instance cause “generates mutiple silder instance” test failed.
You see this is just one line modification of the code to fix the bug but it actually cause my almost 3 hours to find where is the bug and search how to fix this issue. At the end, by the new release version have my name on the changelog file, I think hard debugging is worth it. 👏🏻👏🏻👏🏻
example has shown that an unit testing will find many bugs at some stage of software development, and the cost of modifying them is also low in the early software development stage. In the later stages of software development, however, the discovery and modification of bugs will become more difficult and consume a lot of time and development costs. In this PR I have learned that Testing the software product as early as possible in the life cycle will ensure the best guarantee of efficiency and quality.