Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This PR adds instruction to use it #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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! 🚀

4 changes: 3 additions & 1 deletion smell_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down