A simple Python project demonstrating Unit Testing, Integration Testing, and System Testing methodologies.
This project implements a basic Personal Finance Calculator with comprehensive testing to demonstrate different levels of software testing. The calculator performs common financial calculations such as loan payments, compound interest, and savings goals.
src/
βββ finance_calculator/
β βββ __init__.py # Package initialization
β βββ calculator.py # Core calculation functions
β βββ validator.py # Input validation logic
β βββ main.py # Main application interface
βββ tests/
β βββ __init__.py # Test package initialization
β βββ test_unit.py # Unit tests
β βββ test_integration.py # Integration tests
β βββ test_system.py # System tests
βββ requirements.txt # Project dependencies
βββ README.md # This file
- Simple Interest Calculation: Calculate simple interest on investments
- Compound Interest Calculation: Calculate compound interest with different frequencies
- Loan Payment Calculator: Calculate monthly payments for loans
- Savings Goal Calculator: Determine time needed to reach savings targets
- Input Validation: Comprehensive validation of user inputs
Purpose: Test individual functions and methods in isolation.
Tests Include:
- β Individual calculation functions (simple interest, compound interest, loan payments)
- β Input validation methods
- β Edge cases and boundary conditions
- β Error handling for invalid inputs
- β Mathematical accuracy verification
Example:
def test_simple_interest_calculation(self):
result = self.calculator.calculate_simple_interest(1000, 5, 2)
self.assertEqual(result, 100.0) # (1000 * 5 * 2) / 100 = 100
Purpose: Test how different components work together.
Tests Include:
- β Calculator + Validator integration
- β Main App coordination of components
- β Data flow between modules
- β Component interaction workflows
- β End-to-end calculation processes
Example:
def test_loan_payment_integration(self):
# Tests validator β calculator β result formatting workflow
result = self.app.calculate_loan_payment("15000", "4.5", "4")
self.assertTrue(result['success'])
self.assertIn('monthly_payment', result)
Purpose: Test the complete application from end-user perspective.
Tests Include:
- β Complete user workflows
- β System behavior under various conditions
- β Error handling and recovery
- β Performance characteristics
- β Data integrity across operations
- β User experience consistency
Example:
def test_complete_financial_planning_workflow(self):
# Tests realistic user scenario combining multiple features
savings_result = self.app.calculate_savings_time("50000", "800", "2.5")
loan_result = self.app.calculate_loan_payment("200000", "4.5", "30")
# Verify realistic financial planning results
- Python 3.7 or higher
- pip (Python package installer)
-
Clone or download the project
-
Navigate to the project directory:
cd saba_softwareTesting/src
-
Install dependencies (optional, for enhanced testing):
pip install -r requirements.txt
Method 1: Using the runner script (Recommended)
# Simple runner script that handles paths automatically
python run_app.py
Method 2: Direct execution with PYTHONPATH
# Set Python path and run directly
PYTHONPATH=. python finance_calculator/main.py
Method 3: Using module execution
# Run as module (may require package installation)
python -m finance_calculator.main
Expected Output:
=== Personal Finance Calculator ===
Simple demonstration of financial calculations
1. Loan Payment Calculation:
Monthly Payment: $306.66
Total Interest: $1,039.76
2. Savings Goal Calculation:
Time to reach goal: 2.1 years
Total contributions: $5,040.00
3. Interest Calculation:
Final amount: $1,083.14
Interest earned: $83.14
Method 1: Using the test runner script (Recommended)
# Simple test runner that handles paths automatically
python run_tests.py
Method 2: Using unittest with PYTHONPATH
# Set Python path and run with unittest
PYTHONPATH=. python -m unittest discover tests -v
Method 3: Using pytest (if installed)
# Using pytest with proper path
PYTHONPATH=. pytest tests/ -v
Using the test runner:
python run_tests.py unit # Unit tests only
python run_tests.py integration # Integration tests only
python run_tests.py system # System tests only
Using unittest directly:
Using unittest directly:
PYTHONPATH=. python -m unittest tests.test_unit -v
PYTHONPATH=. python -m unittest tests.test_integration -v
PYTHONPATH=. python -m unittest tests.test_system -v
# Generate coverage report (if coverage package is installed)
coverage run -m pytest tests/
coverage report
coverage html # Generates HTML report
- Unit Tests: ~20 test methods
- Integration Tests: ~8 test methods
- System Tests: ~8 test methods
- Total Tests: ~36 test methods
- β Mathematical calculations
- β Input validation
- β Error handling
- β Component integration
- β User workflows
- β Edge cases and boundaries
- β Performance characteristics
test_calculate_compound_interest (test_unit.TestFinanceCalculator) ... ok
test_calculate_monthly_payment (test_unit.TestFinanceCalculator) ... ok
test_loan_payment_integration (test_integration.TestFinanceAppIntegration) ... ok
test_complete_loan_analysis_workflow (test_system.TestFinanceAppSystem) ... ok
----------------------------------------------------------------------
Ran 36 tests in 0.123s
OK
- Unit Testing: Testing individual components in isolation
- Integration Testing: Testing component interactions and data flow
- System Testing: Testing complete user scenarios and system behavior
- Test Organization: Proper test structure and documentation
- Error Handling: Comprehensive validation and error management
- Code Coverage: Ensuring adequate test coverage across the codebase
- Each test is independent and can run in any order
- Test fixtures (
setUp()
) ensure consistent test environment
- Positive Testing: Testing with valid inputs
- Negative Testing: Testing with invalid inputs
- Boundary Testing: Testing edge cases and limits
- Performance Testing: Basic performance characteristics
- Equality:
assertEqual()
,assertAlmostEqual()
- Boolean:
assertTrue()
,assertFalse()
- Exceptions:
assertRaises()
- Comparisons:
assertGreater()
,assertLess()
- Type Hints: Clear function signatures (could be added for enhancement)
- Documentation: Comprehensive docstrings and comments
- Error Handling: Proper exception handling with meaningful messages
- Validation: Input validation before processing
- Separation of Concerns: Clear separation between calculation, validation, and interface
This basic project can be extended with:
- Mock Testing: Using
unittest.mock
for external dependencies - Parameterized Tests: Testing multiple inputs with single test methods
- Test Data Management: External test data files
- Continuous Integration: Automated testing on code changes
- Performance Benchmarking: Detailed performance testing
- GUI Testing: If a graphical interface is added
This project demonstrates:
- β Simple Python Project (achievable in 1 hour)
- β Unit Testing implementation and examples
- β Integration Testing implementation and examples
- β System Testing implementation and examples
- β Documentation with clear explanations
- β Structured Code with proper organization
- β Real-world Application (financial calculations)
Perfect for demonstrating software testing concepts in an academic setting!
Author: ΩNariman.J
Course: Software Testing
Date: June 2025