From b69a477aa7379f3c39f531abedbf30fea26fbfd0 Mon Sep 17 00:00:00 2001 From: Douglas Cardoso <29078346+douglasdcm@users.noreply.github.com> Date: Sat, 1 Feb 2025 01:26:25 -0300 Subject: [PATCH] Adds instruction to use it - Added a README.md file with the instructions to execute and explanations of the tool - Added a reference to https://testsmells.org/pages/testsmells.html to give more details about each TestSmell --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++ smell_detector.py | 4 ++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..692bd71 --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +# Test Smell Detector + +## 📌 Overview + +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. + +## 🎯 Purpose + +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: +1. **Project Level:** Checks the entire project structure for test-related issues. +2. **Test Case Level:** Analyzes individual test case classes. +3. **Test Method Level:** Examines the methods inside test cases. + +The detected issues are then compiled into an easy-to-read report. + +## 🛠 How It Works + +1. The tool identifies all Python files within the specified directory (including subdirectories). +2. 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. +3. The results are formatted and saved into `output.txt` for review. + +> [!IMPORTANT] +> It reports test smells for tests which enhirit from `unittest.TestCase` + +## 🚀 Installation & Usage + +### Prerequisites +- Python 3.7+ installed on your system + +### Running the Tool + +1. Clone this repository: + ```sh + git clone git@github.com:TestSmells/PythonTestSmellDetector.git + cd PythonTestSmellDetector + ``` +2. Run the tool with: + ```sh + python smell_detector.py /path/to/your/python/project + ``` +3. Check the `output.txt` file for results. + +## 📂 Output +The results will be saved in `output.txt`, formatted as a list of detected test smells along with their locations. + +## 🔥 Example Output +``` +('Test Case has redundant setup', 'tests/test_example.py', 'TestExample') +('Test Method lacks assertion', 'tests/test_example.py', 'test_no_assert') +``` +Each entry specifies: +1. The detected test smell +2. The file where it was found +3. (If applicable) The test case or test method where the issue occurs + +## 📌 Why Use This Tool? +✔ 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! 🚀 + diff --git a/smell_detector.py b/smell_detector.py index c12e2f5..17f13eb 100644 --- a/smell_detector.py +++ b/smell_detector.py @@ -50,7 +50,9 @@ def main(): #Output formatting format_output(results_list) - + print( + "\nFor more details of each issue refer to https://testsmells.org/pages/testsmells.html" + ) else: print("Invalid path given.")