Driven is a -Testing methodology that helps developers to achieve Speed, Robustness and Quality with its specifically structured mechanisms. It is a software development approach where a dev write unittests before the application .

Joe Birch, a Senior Android Engineer at Buffer:
“Following TDD has not only allowed us to write simpler, more understandable code but has allowed us to think more about what we are implementing before actually implementing it. This extra space to think, allows us to understand and test for the different logical paths before getting caught up in implementation details. This, in turn, helps to reduce development time by creating something less error-prone from the start.”

If we unittest but don’t refactor, then we will find (some) bugs earlier. If we unit test and refactor then we will prevent bugs—fewer mistakes will be made, so less to detect. So let’s measure those two outcomes as our primary measures.

Pattern for Arranging and formatting code in UnitTest methods:

Follow – 3 A’s

  1. Arrange all necessary preconditions and inputs.
  2. Act on the object or method under test.
  3. Assert that the expected results have occurred.

Pattern to follow for Naming of unittests:

  1. Given – inputs
  2. When – under certain conditions
  3. Then – output generated

Below are some examples:
a. test_func_raises_zero_division_error_for_divisor_as_zero
b. test_is_adult_false_age_less_than_18
c. test_fail_to_admit_form_if_mandatory_fields_missing

5 major benefits of Test Driven Development:

“A tested code is always given preference to go out on Production. And through writting unit-tests a developer can reduce it’s development effort to re-work if in case there is a new feature enhancement.”

  1. Pushes developer to write a clean and robust code.
  2. Developers have a clear target in mind and that’s very important in agile environment.
  3. Future enhancements would be much easier, as developer would know what to change & where to change, and yes test new code at the same time.
  4. Code functionality can be easily understood as let’s say a developer’s job is filled in by another dev then the new dev can easily understand the code functionality by going through the unit tests.
  5. TDD reduces the chances of accidentally packaging tests with production binaries.
  6. There are many agile engineering practices that a team could adopts and many of those agile engineering practices are dependent on having unit tests.

References:

  1. Metrics: Are We Doing TDD
  2. Clean Code by Robert C Martin
  3. Sample unittest Cases using pytests
  4. Why Use Test-Driven Development?
  5. Principles for Test-Driven Development



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here