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 = 100Purpose: 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.pyMethod 2: Direct execution with PYTHONPATH
# Set Python path and run directly
PYTHONPATH=. python finance_calculator/main.pyMethod 3: Using module execution
# Run as module (may require package installation)
python -m finance_calculator.mainExpected 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.pyMethod 2: Using unittest with PYTHONPATH
# Set Python path and run with unittest
PYTHONPATH=. python -m unittest discover tests -vMethod 3: Using pytest (if installed)
# Using pytest with proper path
PYTHONPATH=. pytest tests/ -vUsing 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 onlyUsing 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.mockfor 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