Skip to content

TDD Report

Iffat Ara Sanzida edited this page Feb 23, 2024 · 3 revisions

Test Driven Development Report for “Dhar-Hobe”- A Bangladeshi Product Renting System

Author:

Iffat Ara Sanzida (IA)

Introduction

Test Driven Development is the process in which test cases are written before the code that validates those cases. It depends on the repetition of a very short development cycle. Test Driven Development is a technique in which automated Unit tests are used to drive the design and free decoupling of dependencies. The steps are as follows: image

  1. Add a test: Write a test case that describes the function completely. In order to make the test cases, the developer must understand the features and requirements using user stories and use cases.
  2. Run all the test cases and make sure that the new test case fails.
  3. Write the code that passes the test case.
  4. Run the test cases.
  5. Refactor code: This is done to remove duplication of code.
  6. Repeat the above-mentioned steps again and again.

Pre-requisites

Tools: Virtual Studio Code
Framework: Python-Django
Unit Testing Tool: Django’s built-in testing framework for unit testing.
For Generating Test Report: pip install coverage

Procedure

  1. Create a tests.py file to write test cases.
    image

  2. From django.test, import Django’s built-in unit testing module TestCase. Also, import RequestFactory and Client for simulating various kinds of test cases.

  3. Import all the files and modules you want to perform unit testing on. In our project’s case, we have imported User, elements of models.py, views.py, and services.py.
    image

  4. Now, write down the test cases. Follow the format mentioned in Unit Testing for test case writing. After adding test cases, to run the test cases of the functions in views.py, write python manage.py test in the terminal. image

Test Case Fails

Feature: Review Add Product Request
We have added 7 test cases, but 3 of them failed.

Test Case 1 Test Case 2
Test Case 3 Test Case 4

At the time of failure, the views functions for the 3 of them were as below:

image 1
image 2 image 3

Test Case Passes

The test_add_product_rqsts_with_no_products was failing as there were no conditions in the views for add_product_rqsts to handle the situation when there are no products for adding requests. After putting the condition, the test case ran successfully for that function. image

We have checked if the function is now performing ok for the test case by the following command.

image image

Also, we have modified the template code in approved_rqsts.html and disapproved_rqsts.html as there were some errors. After modifying the needed codes in views.py file and template files, we have successfully passed all the test cases written in the tests.py file. image

Test Cases Fails

Feature: Review Return Product Request
For TDD, we have written the test cases first for ReturnRequest feature.
image
After running the test cases, we can see that the test case fails.
image
At that time, the body of the return_requests function in views.py was not fully implemented. That’s why test case failed.
image

Test Cases Passes

After modifying the body of the return_requests function in views.py according to the test functions in tests.py, the code looks as following:
image
After implementing the function body according to the test function, the test cases passes.
image

Results

To measure the coverage and accuracy of the test cases upon the modules, write in the command line the following commands.

pip install coverage
coverage run manage.py test
coverage report

Basically, we have tested the modules in our project app and found the following coverage rate:

image

So, the total coverage is 90%.

References

1. Coding Standard

2. Sphinx Documentation Tool

3. SRS

4. TDD Report

5. Sprint 1 Planning

6. Sprint 1 Retrospective Meeting Minutes

7. Sprint 2 Planning

8. CI Report

9. Sprint 2 Retrospective Meeting Minutes

Clone this wiki locally