unit testing - Why do we write test cases? -


so know might say, not question , simple search can give me answer, not true. have read lot testing , importance. know writing test cases helps find potential errors while programming. when read books repeating same abstract definition. after writing lot of test cases, came conclusion not helpful neither preventing potential errors nor increasing product quality.

so imagine have test case below on bunch of our functions:

assert.istrue(dividenumbers(4,3) == 1); assert.istrue(dividenumbers(4,2) == 2); assert.areequal(dividenumbers(8, 4), 2); assert.that(divide(10,2), eq(5)) 

so, while writing test case, trying assert truthfulness of bunch of basic issues 2 equations true? result of function equal desired result? equal? fail? object instance of specified class?,.......

i have worked in lot of software development teams. in times , in teams, after writing test cases encounter situation see functions of assert class can't since basic while errors raises in specific situations not matter of being true, being equal, not being null,....

so, why write test cases? why need them , how can increasing product quality , decreasing potential errors?

the reason write unit tests combinatorics. imagine functions nodes in graph , calls between functions edges. main source node , functions terminate program destination nodes. number of different behaviors program can exhibit equal number of paths source node destination node. exponential in number of nodes , edges. means it infeasible test different behaviors program can exhibit. unit tests come in. each unit test tests 1 node (calling function specific input yields expected output) or 1 edge (calling function specific input generates function call neighboring function) of graph. number of tests required o(|v|+|e|).

this has limitation won't able catch bugs expressed when specific path executed , not expressed when single function called. limitation why important write self contained functions little coupling possible other functions.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -