Comprehensive testing framework for RepoKit functionality including unit tests, integration tests, and end-to-end GitHub deployment tests.
# Run all tests
python tests/run_tests.py
# Run only unit tests (no GitHub token required)
python tests/run_tests.py --unit
# Run integration tests
python tests/run_tests.py --integration
# Run GitHub deployment tests (requires token)
python tests/run_tests.py --github
# Check test environment setup
python tests/run_tests.py --check- No external dependencies - Test core functionality in isolation
- Fast execution - Run in seconds
- No GitHub token required
Tests included:
test_core_functionality.py- Core components (ProjectAnalyzer, GitManager, Config, etc.)
- Test CLI commands - Verify command-line interface works correctly
- Local operations only - No GitHub API calls
- Medium speed - Run in under a minute
Tests included:
test_cli_integration.py- CLI commands and workflows
- Require GitHub token - Test real GitHub API integration
- Create real repositories - Auto-cleaned after tests
- Slower execution - Network operations
Tests included:
test_github_integration.py- GitHub API and credential managementtest_deployment_scenarios.py- Complete deployment scenarios from docs
pip install -e ".[dev]"Create .env.test file in the project root:
# .env.test
REPOKIT_TEST_GITHUB_TOKEN=your_github_personal_access_token_here
REPOKIT_TEST_GITHUB_USER=your-github-username # Optional
REPOKIT_TEST_CLEANUP=true # Auto-cleanup test repos
REPOKIT_TEST_PREFIX=repokit-test- # Test repo prefixImportant: The .env.test file is already in .gitignore and should NEVER be committed!
- Go to https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Select scope:
repo(full repository access) - Copy the token to
.env.test
python tests/run_tests.py# Fast unit tests only
python tests/run_tests.py --unit
# Integration tests (CLI testing)
python tests/run_tests.py --integration
# GitHub API tests (requires token)
python tests/run_tests.py --github
# Deployment scenarios only
python tests/run_tests.py --deployment# Verbose output
python tests/run_tests.py --verbose
# Skip cleanup (leave test repos on GitHub)
python tests/run_tests.py --no-cleanup
# Check environment setup
python tests/run_tests.py --check# Using pytest (if installed)
pytest tests/test_core_functionality.py
# Using unittest directly
python -m unittest tests.test_core_functionality
# Run specific test class
python -m unittest tests.test_core_functionality.TestProjectAnalyzer
# Run specific test method
python -m unittest tests.test_core_functionality.TestProjectAnalyzer.test_detect_python_project-
test_utils.py- Shared test utilities and base classesRepoKitTestCase- Base class with helper methodsTestConfig- Test configurationGitHubTestCleanup- Auto-cleanup for GitHub repos@requires_github_token- Decorator to skip tests without token
-
test_core_functionality.py- Unit tests for core componentsTestProjectAnalyzer- Project analysis logicTestGitManager- Git operationsTestConfig- Configuration systemTestTemplateEngine- Template renderingTestDirectoryAnalyzer- Directory analysis
-
test_cli_integration.py- Integration tests for CLITestCLICommands- Basic command functionalityTestComplexWorkflows- Multi-step workflowsTestErrorHandling- Error cases and edge conditions
-
test_github_integration.py- GitHub API testsTestGitHubIntegration- Real API integrationTestGitHubAPIMocking- Mock API testingTestCredentialManagement- Credential storage
-
test_deployment_scenarios.py- End-to-end deployment tests- Tests all scenarios from
docs/Deployment-Demo.md - Demo 1: Brand new project
- Demo 2: Existing Python project
- Demo 3: Complex multi-branch project
- Demo 4: Legacy project migration
- Tests all scenarios from
class TestNewFeature(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.test_dir, ignore_errors=True)
def test_feature_behavior(self):
# Test implementation
result = my_function()
self.assertEqual(result, expected_value)class TestNewCommand(RepoKitTestCase):
def test_command_execution(self):
stdout, stderr = self.assert_repokit_success([
"new-command", "--option", "value"
])
self.assertIn("expected output", stdout)class TestGitHubFeature(RepoKitTestCase):
@requires_github_token
def test_github_operation(self):
repo_name = self.generate_test_repo_name()
self.github_cleanup.register_repo(repo_name)
# Test GitHub operations
# Cleanup happens automaticallyREPOKIT_TEST_GITHUB_TOKEN- GitHub personal access tokenREPOKIT_TEST_GITHUB_USER- GitHub username (optional)REPOKIT_TEST_GITHUB_ORG- GitHub organization for org tests (optional)REPOKIT_TEST_CLEANUP- Enable/disable auto-cleanup (default: true)REPOKIT_TEST_PREFIX- Prefix for test repository names
# Verify token is loaded
python tests/run_tests.py --check
# Test token manually
curl -H "Authorization: token YOUR_TOKEN" https://api.github.com/user# Run with verbose output
python tests/run_tests.py --verbose
# Run specific failing test
python -m unittest tests.test_name.TestClass.test_method -v# Disable auto-cleanup to inspect repos
python tests/run_tests.py --no-cleanup
# Manually clean up test repos
# Go to GitHub and delete repos starting with "repokit-test-"For CI/CD pipelines:
# Example GitHub Actions
- name: Run RepoKit Tests
env:
REPOKIT_TEST_GITHUB_TOKEN: ${{ secrets.REPOKIT_TEST_TOKEN }}
run: |
pip install -e ".[dev]"
python tests/run_tests.pyTo run tests with coverage:
# Install coverage
pip install coverage
# Run with coverage
coverage run -m unittest discover tests
# Generate report
coverage report
coverage html # Creates htmlcov/index.html- Always use test prefixes - All test repos start with
repokit-test- - Register repos for cleanup - Use
self.github_cleanup.register_repo() - Use helper methods - Leverage
RepoKitTestCaseutilities - Test both success and failure - Include error cases
- Mock when possible - Use
MockGitHubAPIfor unit tests - Keep tokens secure - Never commit
.env.testor tokens
When adding new features to RepoKit:
- Add unit tests for new components
- Add integration tests for new CLI commands
- Add GitHub tests if feature involves deployment
- Update test documentation
- Ensure all tests pass before submitting PR
Happy testing! 🧪