Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The project does not employ a formal, automated testing framework like pytest or jest. Instead, the testing strategy is a manual, multi-faceted approach that relies on standalone scripts for core logic validation, cross-verification using generated Excel files, manual API endpoint testing via interactive documentation, and visual validation through the frontend application. This strategy ensures the correctness of the core TOPSIS algorithm and data processing pipeline through direct execution, data comparison, and user-driven inspection.
The primary methods of verification are:
- Standalone Script Execution: Running Python scripts to test the TOPSIS algorithm in isolation.
- Excel-Based Cross-Validation: Generating Excel sheets with embedded formulas to verify the Python logic against a separate calculation engine.
- Manual API Testing: Using the FastAPI-generated documentation to interact with and validate API endpoints.
- Visual Frontend Verification: Interacting with the UI to confirm that data is displayed correctly and calculations match expectations.
Sources: topsis_spk.py, generate_excel_formula.py, backend/main.py, frontend/src/components/CalculationView.tsx
1. Core Logic Verification (Standalone Scripts)
The core TOPSIS algorithm, encapsulated in the TOPSISAnalyzer class, is tested using the standalone topsis_spk.py script. This script serves as a command-line test runner for the main analysis logic.
Execution Flow
The script performs a full, end-to-end analysis outside the context of the web application, making it an essential tool for integration testing of the data processing and algorithm implementation.
The following diagram illustrates the testing workflow using topsis_spk.py.
Sources: topsis_spk.py:321-332
Test Artifacts
Running main() in topsis_spk.py produces several artifacts that can be manually inspected to verify the correctness of the calculation:
| Artifact | Description | File |
|---|---|---|
| Console Report | A formatted summary of the top 10 rankings and the best recommendation, printed directly to the console. | topsis_spk.py |
| Full Results CSV | A CSV file containing the complete ranked list of all alternatives with their scores. | hasil_topsis_lengkap.csv |
| Top 5 Text File | A detailed text file describing the top 5 recommended vendors and their attributes. | rekomendasi_top5.txt |
| Visualization PNG | A comprehensive plot with multiple charts (bar, radar, scatter, heatmap) visualizing the results. | hasil_visualisasi_topsis.png |
Sources: topsis_spk.py:110-161, 300-320
2. Data and Formula Validation (Excel Generation)
A key part of the testing strategy involves using Microsoft Excel as an independent verification tool. The project includes scripts to generate Excel workbooks where the entire TOPSIS calculation is performed using native Excel formulas. This allows for a direct comparison between the Python implementation and the Excel implementation.
Excel Generation Scripts
| Script | Purpose | Output File |
|---|---|---|
generate_excel_level.py | Creates a user-friendly Excel file where inputs are based on levels (1-5). It contains sheets that convert these levels to numerical values and then run the full TOPSIS calculation using formulas. | TOPSIS_Input_Level.xlsx |
generate_excel_formula.py | Creates a similar Excel file but takes direct numerical inputs. It also contains the full TOPSIS calculation implemented with Excel formulas. | TOPSIS_Rumus_Otomatis.xlsx |
Sources: generate_excel_level.py, generate_excel_formula.py
Verification Workflow
This method allows a developer or tester to change input values (criteria or weights) in the generated Excel file and see the results calculated by Excel's engine. These results can then be compared against the output from the Python backend to ensure consistency.
The diagram below shows how Excel is used for cross-validation.
Sources: generate_excel_formula.py:108-198
The script generate_excel_formula.py populates a worksheet with formulas that directly reference input cells, creating a dynamic calculation chain. For example, the normalized matrix cell B5 is calculated with:
='1. Data Input'!D4/SQRT(SUMPRODUCT('1. Data-Input'!$D$4:$D$23,'1. Data-Input'!$D$4:$D$23))
This ensures that any change in the input sheet '1. Data Input' is automatically reflected in the final ranking.
Sources: generate_excel_formula.py:126-137
3. Backend API Testing
The backend is built with FastAPI, which provides automatically generated, interactive API documentation. This feature is the primary tool for manually testing the API endpoints.
Accessing Test Interface
The interactive documentation is available at the /docs endpoint of the running backend server (e.g., http://localhost:8000/docs). This UI allows developers to execute requests against each endpoint, provide parameters, and inspect the responses.
Sources: README.md:120-121, QUICKSTART.md:73-77
Key Endpoints for Testing
The following endpoints defined in backend/main.py are critical for testing:
| Method | Endpoint | Description | Testing Focus |
|---|---|---|---|
POST | /api/login | Authenticates a user. | Correct handling of valid/invalid credentials. |
GET | /api/data | Retrieves all vendor data from the Excel file. | Data integrity and correct parsing from TOPSIS_Input_Level.xlsx. |
POST | /api/calculate | Runs the simple TOPSIS calculation. | Correctness of final scores and ranking based on input weights. |
POST | /api/calculate-detail | Runs TOPSIS and returns all intermediate matrices. | Crucial for step-by-step validation. Ensures each matrix (Normalized, Weighted, etc.) is correct. |
POST | /api/data | Adds a new vendor. | Correctly appends data to the Excel file. |
PUT | /api/data/{vendor_no} | Updates an existing vendor. | Correctly modifies data in the Excel file. |
DELETE | /api/data/{vendor_no} | Deletes a vendor. | Correctly removes data from the Excel file. |
Sources: backend/main.py:192-195, 349-352, 490-493, 521-524
Test Sequence Example
The following sequence diagram shows a typical manual test for the detailed calculation endpoint.
Sources: backend/main.py:490-598
4. Visual Frontend Verification
The React frontend provides a user-friendly interface to visually test and verify the results from the backend. The CalculationView component is specifically designed for this purpose.
Step-by-Step Verification UI
The CalculationView.tsx component fetches data from the /api/calculate-detail endpoint and renders each step of the TOPSIS process in a series of collapsible cards. This allows a user to:
- Input custom weights.
- Trigger a calculation.
- Inspect each matrix (Input, Normalized, Weighted, etc.) one by one.
- Compare the final ranked list against their expectations.
This provides an immediate visual feedback loop for testing the entire pipeline from the user's perspective.
The following diagram shows the data flow for visual verification.
The UI explicitly displays the formulas used for each step, such as rij = xij / √(Σxij²), which aids in the manual verification process by reminding the tester of the expected calculation for each matrix.
Sources: frontend/src/components/CalculationView.tsx:128-151