Test Driven Development
Today, we are moving on to challenge 2 of the shopping list application. For this challenge, we are required to use several tools, development techniques and guidelines including Flask, Pylint, Object Oriented Development, Test Driven Development (TDD), PEP8 etc to develop features enabling the user to Create Review Update Delete (CRUD) within the application as well as register and log in a user.
While it is one of the most crucial parts of development, TDD is among the more tricky techniques that I have been implementing today. From my understanding, TDD is a development technique that requires a developer to test specific features of their application using different test cases. Before any tests are written, the developer needs to fully understand the requirements of the different applications in order to write relevant tests.
Conventionally, tests for any feature or application are written before any code for functionality. While this is the convention and it definitely makes sense to write your tests before any other code as to keep track of your application features, I find it challenging to write tests before my functionality code. So basically I chose to do it the other way around by writing code for functionality then the tests follow as follows;
After the code for functionality is written, I went ahead to create my test folders prefixed with “test” so as to differentiate them from other folders in my application. After creating the test folder, I imported the unittest framework followed by any classes that I will be implementing in my tests. Secondly, I created a class to contain the different test cases for the feature would be testing first. Initially, each test is written to fail to ensure that the test actually works and thereafter refactored so that it passes. At the end of the day, I was able to write quite a few tests (38 tests) for my application which was a great achievement.
The great thing about TDD is that you can never have too many tests, in fact, the more the better so I look forward to more testing with unittest and other frameworks as I find my feet in this world of Test Driven Development. Gakyali Mabaga (It is just the beginning)