Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page: - [tests/test_model.py](https://github.com/Fahri-Hilm/Analisis-Sentiment-Data_Mining/blob/HEAD/tests/test_model.py) - [dashboard-next/DEPLOYMENT_CHECKLIST.md](https://github.com/Fahri-Hilm/Analisis-Sentiment-Data_Mining/blob/HEAD/dashboard-next/DEPLOYMENT_CHECKLIST.md) - [CONTRIBUTING.md](https://github.com/Fahri-Hilm/Analisis-Sentiment-Data_Mining/blob/HEAD/CONTRIBUTING.md) - [PERFORMANCE_OPTIMIZATION_REPORT.md](https://github.com/Fahri-Hilm/Analisis-Sentiment-Data_Mining/blob/HEAD/PERFORMANCE_OPTIMIZATION_REPORT.md) - [src/modeling/unified_sentiment_scorer.py](https://github.com/Fahri-Hilm/Analisis-Sentiment-Data_Mining/blob/HEAD/src/modeling/unified_sentiment_scorer.py) - [DEPLOYMENT_SUMMARY.md](https://github.com/Fahri-Hilm/Analisis-Sentiment-Data_Mining/blob/HEAD/DEPLOYMENT_SUMMARY.md)The project employs a multi-layered testing strategy to ensure the reliability, performance, and correctness of both the backend sentiment analysis models and the frontend dashboard. The strategy encompasses automated unit and integration tests for the Python backend, a comprehensive manual checklist for frontend functionality and performance, and a defined testing protocol for new contributions.
This approach ensures that the data processing pipeline is sound, the machine learning models are accurate and performant, the user interface is functional and responsive, and the system as a whole is ready for deployment.
Backend Model Testing
The core of the backend testing is managed by pytest and focuses on the sentiment analysis model and its associated data. The test suite, located in tests/test_model.py, is structured to cover data integrity, model functionality, performance benchmarks, and end-to-end pipeline validation.
Sources: tests/test_model.py, CONTRIBUTING.md:19
Test Execution Flow
The following diagram illustrates the execution flow of the backend test suite.
This diagram shows the different categories of tests executed by the pytest command.
Sources: tests/test_model.py
Test Case Summary
The test suite includes a variety of checks to validate different aspects of the model and data.
| Test Category | Test Case | Description |
|---|---|---|
| Data Integrity | test_data_exists | Verifies the existence of the processed CSV file. |
test_data_structure | Checks for required columns (clean_text, sentiment_label, confidence). | |
test_data_not_empty | Ensures the dataset contains a minimum number of rows (>= 8000). | |
test_no_missing_values | Asserts that critical columns have no null values. | |
test_confidence_range | Confirms that confidence scores are between 0 and 1. | |
| Model Functionality | test_model_exists | Verifies the existence of the pickled model file (svm_best_regularized.pkl). |
test_model_loads | Ensures the model can be loaded without errors using pickle. | |
test_model_prediction | Tests if the loaded model can successfully make predictions on sample texts. | |
| Model Performance | test_model_accuracy | Checks if the model's test accuracy meets a minimum threshold (>= 65%). |
test_confidence_threshold | Checks if the average confidence score meets a minimum threshold (>= 70%). | |
| Integration | test_end_to_end_pipeline | Runs a single text through the prediction pipeline to ensure it works from start to finish. |
Sources: tests/test_model.py:5-83
Performance and Accuracy Validation
A critical part of the backend testing is to ensure the model meets predefined performance standards. This is done by loading metrics from a results file and asserting against them.
# tests/test_model.py:68-74
def test_model_accuracy():
"""Test if model meets minimum accuracy threshold."""
import json
with open("data/models/best_regularization_results.json", "r") as f:
results = json.load(f)
accuracy = results.get('test_accuracy', 0)
assert accuracy >= 0.65, f"Accuracy too low: {accuracy:.2%}"
Sources: tests/test_model.py:68-74
End-to-End Pipeline Test
An integration test validates the entire prediction flow, from raw text input to receiving a prediction from the loaded model. This ensures all components of the model pipeline work together correctly.
This sequence diagram shows the steps in the end-to-end pipeline test.
Sources: tests/test_model.py:82-93
Unified Scorer Self-Testing
The UnifiedSentimentScorer includes its own set of tests within its if __name__ == "__main__" block. This allows for quick, standalone validation of the scorer's logic across its different behavioral modes (static, realtime, unified).
# src/modeling/unified_sentiment_scorer.py:279-307
if __name__ == "__main__":
# Test unified scoring system
scorer = UnifiedSentimentScorer()
print("🎯 Testing Unified Sentiment Scoring System")
# ...
model_types = ["static", "realtime", "unified"]
for model_type in model_types:
print(f"\n📊 Testing {model_type.upper()} model behavior:")
# ...
results = scorer.batch_analyze(test_texts, model_type)
# ...
Sources: src/modeling/unified_sentiment_scorer.py:279-307
Frontend and Deployment Testing
The testing strategy for the dashboard-next frontend is primarily guided by a comprehensive checklist used before and after deployment. This ensures functionality, performance, and user experience meet project standards.
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md
Pre-Deployment Checklist
Before any deployment, a series of checks are performed to ensure the application is stable and ready. This includes build verification and running various tests.
This flowchart outlines the key verification steps before deploying the frontend application.
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:5-13
Functionality and Performance Testing
The deployment checklist specifies numerous manual tests to be conducted.
Functionality Tests:
- Dashboard loads correctly
- All navigation links work
- API endpoints respond as expected
- Charts render properly with accurate data
- Responsive design works across devices
Performance Tests:
- API response time < 5ms (cached)
- Page load time < 2s
- Optimized bundle size
- No memory leaks
- Smooth animations
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:17-31
Performance Benchmarking
Specific tools and commands are defined for benchmarking the deployed application's performance.
# Lighthouse audit
npx lighthouse https://your-domain.com --view
# Load testing
npx autocannon -c 100 -d 30 https://your-domain.com
# Bundle analysis
npm run build -- --analyze
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:89-97
Post-Deployment Monitoring and Validation
After deployment, a structured monitoring plan is executed to catch any issues in the live environment. This includes immediate checks, performance monitoring over the first hour, and user experience analysis over the first day. Additionally, specific features are targeted for testing to validate new functionality.
Key Features to Test (v5.0.0):
- Smart Comment Filter: Verify that only relevant comments are displayed when the filter is active.
- Aggressive Sentiment Analysis: Observe the reduction in "neutral" results and check the AI reasoning.
- Real-time Processing: Ensure the live analysis page streams and processes comments correctly.
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:65-81, DEPLOYMENT_SUMMARY.md:60-77
Success Criteria
The project defines clear success criteria for performance, reliability, and user experience, which guide the testing and quality assurance process.
| Category | Metric | Target |
|---|---|---|
| Performance | Lighthouse score | > 90 |
| API response | < 100ms | |
| Page load | < 2s | |
| Reliability | Uptime | > 99.9% |
| Error rate | < 0.1% | |
| User Experience | Interactions | Smooth |
| Design | Responsive |
Sources: dashboard-next/DEPLOYMENT_CHECKLIST.md:107-122, PERFORMANCE_OPTIMIZATION_REPORT.md:73-80
Contribution Workflow Testing
The contribution guidelines mandate that developers test their changes before creating a pull request. This ensures that new code integrates correctly and does not introduce regressions.
The required testing commands are:
# Run backend tests
pytest tests/
# Test the dashboard
cd dashboard-next
npm run dev
This process ensures that both the Python backend and the Next.js frontend are validated as part of the development cycle.
Sources: CONTRIBUTING.md:19-24
Summary
The testing strategy for this project is robust and multi-faceted. It combines automated pytest tests for the backend model's data, functionality, and performance with a detailed manual checklist for the frontend's UI, UX, and performance. The strategy is integrated into the development and deployment lifecycle, with clear guidelines for contributors and rigorous post-deployment monitoring. This comprehensive approach ensures a high-quality, reliable, and performant application.