Skip to content
Closed
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
36 changes: 36 additions & 0 deletions courseProjectCode/Metrics/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Setup and Running Testability Metrics

## Setup Instructions

1. Clone the repository

- git clone your-repo-url
- cd cli-swen777

2. Install dependencies and setup environment

- make

The above command will:
- Create a virtual environment inside ./venv
- Install all dependencies
- Install HTTPie in editable mode
- Run the test suite once

3. Activate the virtual environment

- source venv/bin/activate

4. Run the testability metrics script

- python3 courseProjectCode/Metrics/Testability.py

The above command will:

- Run all tests with coverage enabled
- Generate a coverage report
- Output the total number of test cases and test suites

![](report.png)


27 changes: 27 additions & 0 deletions courseProjectCode/Metrics/Testability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess # Import subprocess to run shell commands from Python

def run_command(command): # function to execute shell command and returns its output as a string
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout.strip()

def count_test_cases(): # Fucntion to count total test cases by collecting pytest functions
output = run_command("pytest --collect-only | grep '<Function' | wc -l")
return int(output) if output else 0

def count_test_suites():# Fucntion to count total test suites by collecting pytest modules
output = run_command("pytest --collect-only | grep '<Module' | wc -l")
return int(output) if output else 0

def run_coverage(): # Runs pytest with coverage to measure code coverage and display the report
print("\nRunning tests with coverage...")
subprocess.run("coverage run --source=httpie -m pytest || true", shell=True)
print("\nCoverage Report:")
subprocess.run("coverage report", shell=True)

if __name__ == "__main__":
print("Collecting Testability Metrics for HTTPie...\n")
run_coverage()
total_tests = count_test_cases()
total_suites = count_test_suites()
print(f"Total test cases: {total_tests}")
print(f"Total test suites (modules): {total_suites}")
Binary file added courseProjectCode/Metrics/report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading