Skip to content

Backend Testing Part of Milestone 2 Review

oguzpancuk edited this page Nov 29, 2024 · 1 revision

Testing

Backend Testing Strategy

Testing for the backend is managed using a combination of unit tests and integration tests. For every backend endpoint, unit tests and integration tests are implemented to cover success and failure scenarios, including edge cases.

  • Test Placement: All test cases are organized within the test.py file, which inherits from django.test.TestCase.
  • Test Execution: Tests can be executed using the command python manage.py test.

Unit Tests

Unit tests focus on verifying individual components or functions to ensure they work correctly in isolation. They are designed to validate the behavior of specific parts of the code, such as serializers, models, or methods within views, without relying on external dependencies. For instance:

  • News Endpoint Unit Tests:
    • A unit test simulates the retrieval of news from external RSS feeds, mocking the feedparser library to ensure accurate handling of RSS data.
    • These tests verify that the backend returns the correct response structure, including fields like title, link, author, and published.

Integration Tests

Integration tests validate the interaction between different parts of the application to ensure they function correctly as a cohesive system. These tests cover the end-to-end functionality of features, such as views, serializers, and external services.

  • News Endpoint Integration Tests:
    • These tests cover scenarios where valid and invalid feed names are submitted to the API.
    • They validate that the API returns the correct status codes (200, 404, 400) and appropriate error messages when handling valid, invalid, or missing input parameters.

Specific Testing Scenarios

News Endpoint:
Integration and unit tests for the news_feed endpoint are implemented to ensure reliable functionality. For example:

  • Valid RSS feeds such as "financial times" are processed, and the API response structure is verified.
  • Invalid feed names are rejected with appropriate error messages.
  • Missing required parameters result in a 400 BAD REQUEST status.

Data Population Strategy (Planned)

To facilitate testing and development, a data population strategy using Faker has been outlined. While not implemented yet, the plan includes:

  1. Defining data requirements for models like Currency, Stock, Tag, Portfolio, Post, and Comment.
  2. Creating a populate.py script to handle mock data generation, including foreign key relationships.
  3. Automating data population during Docker container startup via docker-compose.yml and migrations.

This strategy will ensure realistic mock data for tests, improving their reliability.

📋 Lab Reports

📆 Meeting Notes

🧪 Lab Meetings

🗓️ General Meetings

⚙️ Backend Meetings

📝 Milestone Reports

📑 Project Artifacts

📖 Manuals

📑 Other Artifacts

📋 Software Requirements Specification

📊 Software Design Documents

✏️ User Scenarios & Mockups

🗂 Project Plan

🧪 Unit Tests

📜 Docs

👥 Team

SemanticFlix Archieve

📝 Milestone Reports

📆 Meeting Notes

🧾 Requirements

Project Plan

📊 Diagrams

👥 Team

📝 Researches

Repository Documentations

📁 Templates

Clone this wiki locally