feat: Add make test-new for quick test file template creation
- Add test-new make target for generating test file templates - Interactive prompt for test name with validation - Generates structured test class with setup/teardown methods - Includes basic functionality, edge cases, and error handling placeholders - Follows TDD best practices with Arrange-Act-Assert pattern - Auto-generates class names from test names (snake_case to PascalCase) Usage: make test-new Then enter test name when prompted (e.g., "schema_validation") 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
73
Makefile
73
Makefile
@@ -1,7 +1,7 @@
|
||||
# MarkiTect - Advanced Markdown Engine
|
||||
# Makefile for common development tasks
|
||||
|
||||
.PHONY: help setup install test build clean update status dev lint format check-deps venv-status update-digest add-diary-entry list-issues show-issue list-open-issues test-from-issue tdd-start tdd-add-test tdd-finish tdd-status test-status
|
||||
.PHONY: help setup install test build clean update status dev lint format check-deps venv-status update-digest add-diary-entry list-issues show-issue list-open-issues test-from-issue tdd-start tdd-add-test tdd-finish tdd-status test-status test-new
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@@ -20,6 +20,7 @@ help:
|
||||
@echo "Development:"
|
||||
@echo " test - Run all tests"
|
||||
@echo " test-status - Show test status summary without re-running"
|
||||
@echo " test-new - Create new test file template"
|
||||
@echo " build - Build the package"
|
||||
@echo " lint - Run code linting"
|
||||
@echo " format - Format code"
|
||||
@@ -327,3 +328,73 @@ test-status: $(VENV)/bin/activate
|
||||
else \
|
||||
echo "💡 Generate detailed report with test run data"; \
|
||||
fi
|
||||
|
||||
# Create new test file template
|
||||
test-new: $(VENV)/bin/activate
|
||||
@echo "🧪 Creating new test file"
|
||||
@echo "========================"
|
||||
@echo ""
|
||||
@read -p "Test name (e.g., feature_name): " test_name; \
|
||||
if [ -z "$$test_name" ]; then \
|
||||
echo "❌ Test name cannot be empty"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
test_file="tests/test_$$test_name.py"; \
|
||||
if [ -f "$$test_file" ]; then \
|
||||
echo "❌ Test file already exists: $$test_file"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
echo "📝 Creating: $$test_file"; \
|
||||
echo '"""' > "$$test_file"; \
|
||||
echo "Test for $$test_name functionality." >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo "This test module validates [describe what you're testing]." >> "$$test_file"; \
|
||||
echo '"""' >> "$$test_file"; \
|
||||
echo "import pytest" >> "$$test_file"; \
|
||||
echo "from markitect import [import what you need]" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
class_name=$$(echo $$test_name | sed 's/_/ /g' | sed 's/\b\w/\U&/g' | sed 's/ //g'); \
|
||||
echo "class Test$$class_name:" >> "$$test_file"; \
|
||||
echo ' """Test suite for '$$test_name' functionality."""' >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " def setup_method(self):" >> "$$test_file"; \
|
||||
echo ' """Set up test environment."""' >> "$$test_file"; \
|
||||
echo " pass" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " def teardown_method(self):" >> "$$test_file"; \
|
||||
echo ' """Clean up after tests."""' >> "$$test_file"; \
|
||||
echo " pass" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " def test_basic_functionality(self):" >> "$$test_file"; \
|
||||
echo ' """Test basic '$$test_name' functionality."""' >> "$$test_file"; \
|
||||
echo " # Arrange" >> "$$test_file"; \
|
||||
echo " # TODO: Set up test data" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " # Act" >> "$$test_file"; \
|
||||
echo " # TODO: Execute the functionality" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " # Assert" >> "$$test_file"; \
|
||||
echo " # TODO: Verify expected results" >> "$$test_file"; \
|
||||
echo " assert True # Replace with actual assertions" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " def test_edge_cases(self):" >> "$$test_file"; \
|
||||
echo ' """Test edge cases for '$$test_name'."""' >> "$$test_file"; \
|
||||
echo " # TODO: Test boundary conditions, empty inputs, etc." >> "$$test_file"; \
|
||||
echo " pass" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo " def test_error_handling(self):" >> "$$test_file"; \
|
||||
echo ' """Test error handling for '$$test_name'."""' >> "$$test_file"; \
|
||||
echo " # TODO: Test invalid inputs, exception cases" >> "$$test_file"; \
|
||||
echo " pass" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo "" >> "$$test_file"; \
|
||||
echo "if __name__ == '__main__':" >> "$$test_file"; \
|
||||
echo " pytest.main([__file__, '-v'])" >> "$$test_file"; \
|
||||
echo "✅ Test file created: $$test_file"; \
|
||||
echo ""; \
|
||||
echo "🎯 Next steps:"; \
|
||||
echo " 1. Edit the test file to add your specific tests"; \
|
||||
echo " 2. Run: make test to check if it works"; \
|
||||
echo " 3. Implement the actual functionality"; \
|
||||
echo " 4. Run tests again to verify (TDD cycle)"
|
||||
|
||||
Reference in New Issue
Block a user