The Test Smell Detector is a Python-based tool designed to analyze a given project directory and detect "test smells." Test smells are patterns in test code that may lead to maintainability issues, reduce test effectiveness, or introduce hidden bugs. This tool helps developers improve the quality of their test suites by providing insights into potential problem areas.
Many software projects suffer from poor test quality due to test smells such as:
- Lack of proper structure
- Inefficient test cases
- Redundant or poorly maintained test methods
This tool systematically scans a given Python project directory and evaluates test-related files across three levels:
- Project Level: Checks the entire project structure for test-related issues.
- Test Case Level: Analyzes individual test case classes.
- Test Method Level: Examines the methods inside test cases.
The detected issues are then compiled into an easy-to-read report.
- The tool identifies all Python files within the specified directory (including subdirectories).
- It processes the files through three rule-checking stages:
- Project Level: Evaluates the overall test organization.
- Test Case Level: Analyzes test case structures.
- Test Method Level: Examines individual test methods.
- The results are formatted and saved into
output.txtfor review.
Important
It reports test smells for tests which enhirit from unittest.TestCase
- Python 3.7+ installed on your system
- Clone this repository:
git clone git@github.com:TestSmells/PythonTestSmellDetector.git cd PythonTestSmellDetector - Run the tool with:
python smell_detector.py /path/to/your/python/project
- Check the
output.txtfile for results.
The results will be saved in output.txt, formatted as a list of detected test smells along with their locations.
('Test Case has redundant setup', 'tests/test_example.py', 'TestExample')
('Test Method lacks assertion', 'tests/test_example.py', 'test_no_assert')
Each entry specifies:
- The detected test smell
- The file where it was found
- (If applicable) The test case or test method where the issue occurs
✔ Helps improve test quality by identifying bad practices. ✔ Easy-to-use CLI tool requiring minimal setup. ✔ Supports Python projects of any scale. ✔ Provides actionable insights to refactor test code.
Contributions & Feedback: Feel free to submit issues or contribute to improving this tool! 🚀