Enterprise-grade test automation framework for IoT platforms with MQTT messaging, REST APIs, and certificate-based security (mTLS). Built with Robot Framework and designed for production-scale testing.
- MQTT Testing - Full pub/sub testing with QoS 0, 1, 2 support
- mTLS Authentication - Certificate-based device authentication
- REST API Testing - Comprehensive API testing with JWT authentication
- Performance Testing - Response time and throughput validation
- CI/CD Integration - GitHub Actions pipeline with parallel execution
- Custom Libraries - Purpose-built Python libraries for IoT testing
- Docker Support - Containerized test environment
- ✅ Device Management API (CRUD operations)
- ✅ MQTT Publish/Subscribe (all QoS levels)
- ✅ Authentication & Authorization (JWT, mTLS)
- ✅ Automation Rules Engine
- ✅ Certificate Lifecycle Management
- ✅ End-to-End Integration Scenarios
- ✅ Performance & Load Testing
- ✅ Security & Negative Testing
- Python 3.11+
- Docker & Docker Compose
- Git
We now have a modern, interactive CLI with beautiful terminal UI:
# Interactive mode - just run and select from menu
python3 cli_enhanced.py
# Or use direct commands
python3 cli_enhanced.py setup
python3 cli_enhanced.py run --suite smoke
python3 cli_enhanced.py servicesFeatures:
- 🎨 Beautiful interactive menus
- 📊 Rich progress indicators
- 🔍 Tree view of test structure
- ✨ One-click report opening
- 🚀 Quick start wizard
See CLI_README.md for full documentation.
# Clone the repository
git clone https://github.com/mankin3n/MQTTest.git
cd MQTTest
# Run setup (installs dependencies & generates certificates)
python3 cli_enhanced.py setup
# or use the original CLI:
python3 cli.py setup
# Start services (MQTT broker & Mock API)
python3 cli_enhanced.py services
# or: python3 cli.py services
# Run smoke tests
python3 cli.py run --suite smoke.
├── cli.py # CLI interface for test execution
├── requirements.txt # Python dependencies
├── docker-compose.yml # Service orchestration
│
├── config/ # Environment configurations
│ ├── __init__.py
│ └── environments/
│ ├── dev.yaml # Development config
│ └── ci.yaml # CI/CD config
│
├── libraries/ # Custom test libraries
│ ├── api/ # REST API library
│ │ ├── __init__.py
│ │ └── APILibrary.py # HTTP operations, JWT auth
│ ├── mqtt/ # MQTT library
│ │ ├── __init__.py
│ │ └── MQTTLibrary.py # MQTT pub/sub, mTLS
│ └── utils/ # Utility libraries
│ ├── __init__.py
│ └── TestDataFactory.py # Test data generation
│
├── resources/ # Robot Framework resources
│ ├── common.robot # Common keywords & setup
│ ├── device_management.robot # Device operations
│ └── automation_rules.robot # Automation testing
│
├── tests/ # Test suites
│ ├── api/
│ │ └── test_device_api.robot # API tests (TC001-TC010)
│ ├── mqtt/
│ │ └── test_mqtt_pubsub.robot # MQTT tests (TC011-TC020)
│ ├── security/
│ │ └── test_authentication.robot # Security tests (TC021-TC030)
│ └── integration/
│ └── test_end_to_end.robot # Integration tests (TC031-TC040)
│
├── certs/ # Test certificates
│ ├── ca/ # Certificate Authority
│ ├── broker/ # MQTT broker certs
│ ├── devices/ # Device certificates
│ └── clients/ # Client certificates
│
├── scripts/
│ ├── generate_certs.py # Certificate generation
│ ├── cert_manager.sh # Certificate management
│ └── setup.sh # Environment setup
│
├── docker/
│ ├── mosquitto.conf # MQTT broker config (TLS)
│ ├── mock-api.py # Mock REST API server
│ └── Dockerfile.mock-api # API Docker image
│
└── .github/
└── workflows/
└── ci.yml # GitHub Actions pipeline
The framework includes a comprehensive CLI for test execution:
# Setup environment
python3 cli.py setup # Install deps & generate certs
python3 cli.py setup --skip-deps # Skip dependency installation
# Manage services
python3 cli.py services # Start Docker services
python3 cli.py stop # Stop services
python3 cli.py status # Check service status
# Run tests
python3 cli.py run --suite smoke # Run smoke tests
python3 cli.py run --suite api # Run API tests
python3 cli.py run --suite mqtt # Run MQTT tests
python3 cli.py run --suite security # Run security tests
python3 cli.py run --suite integration # Run integration tests
python3 cli.py run --suite all # Run all tests
# Advanced options
python3 cli.py run --suite api --parallel # Parallel execution
python3 cli.py run --tags positive # Run specific tags
python3 cli.py run --env ci # Use CI config
python3 cli.py run --verbose # Verbose output
python3 cli.py run --dry-run # Preview without running
# Utilities
python3 cli.py list-tests # List all tests
python3 cli.py certs # Show certificate status
python3 cli.py clean # Clean reports
python3 cli.py info # Show project info# Activate virtual environment (if used)
source venv/bin/activate
# Run specific test file
robot --variable ENV:dev tests/api/test_device_api.robot
# Run tests with tags
robot --include smoke --variable ENV:dev tests/
# Run tests in parallel
pabot --processes 4 --variable ENV:dev tests/
# Generate detailed report
robot --loglevel DEBUG --outputdir reports tests/# Build and run tests in Docker
docker-compose up -d # Start services
docker-compose --profile test up # Run tests in container
docker-compose down # Stop all services
# Run specific test suite in Docker
docker-compose run test-runner robot --include api tests/The framework uses mTLS for MQTT broker authentication:
# Using Python script
python3 scripts/generate_certs.py
# Using shell script
./scripts/cert_manager.sh generatecerts/
├── ca/
│ ├── ca.crt # Root CA certificate
│ └── ca.key # CA private key
├── broker/
│ ├── broker.crt # Mosquitto broker certificate
│ └── broker.key # Broker private key
├── devices/
│ ├── device001.crt # Device certificates
│ ├── device001.key
│ └── ...
└── clients/
├── test-client.crt # Test client certificate
└── test-client.key
# List all certificates
./scripts/cert_manager.sh list
# Verify certificate
./scripts/cert_manager.sh verify certs/ca/ca.crt
# Check expiry dates
./scripts/cert_manager.sh expiry
# Clean and regenerate
./scripts/cert_manager.sh clean
python3 scripts/generate_certs.pyTC001: Register new light deviceTC002: Register thermostat deviceTC003: Get device statusTC004: Update device configurationTC005: Delete deviceTC006: Authentication requiredTC007: Non-existent device returns 404TC008: Invalid data validationTC009: Batch device registrationTC010: Performance verification
TC011-TC013: QoS 0, 1, 2 testingTC014: Wildcard topic subscriptionTC015: Retained messagesTC016: Device telemetry publishingTC017: Device command handlingTC018: Multiple subscriptionsTC019: Unsubscribe functionalityTC020: Metrics tracking
TC021-TC026: JWT authenticationTC027-TC029: Certificate-based authTC030: Failed auth tracking
TC031: Complete device lifecycleTC032: Command and response flowTC033: Automation rule end-to-endTC034: Multi-device telemetryTC035: Certificate provisioningTC036-TC037: Performance testingTC038: Multiple automation rulesTC039: Status monitoringTC040: System health check
- Port: 8883 (MQTT over TLS)
- WebSocket: 9001 (WSS)
- Authentication: Client certificates (mTLS)
- Configuration:
docker/mosquitto.conf
- Port: 8000
- Endpoints:
POST /api/v1/devices- Register deviceGET /api/v1/devices/{id}- Get devicePUT /api/v1/devices/{id}- Update deviceDELETE /api/v1/devices/{id}- Delete devicePOST /api/v1/automation-rules- Create rulePOST /api/v1/certificates/provision- Provision certGET /health- Health check
home/{device_id}/telemetry # Device → Cloud (telemetry data)
home/{device_id}/command # Cloud → Device (commands)
home/{device_id}/status # Device status updates
home/events/automation # Automation rule triggers
GitHub Actions workflow includes:
- Code Quality - Linting (Black, Flake8)
- Certificate Setup - Auto-generate test certs
- Parallel Test Execution:
- API Tests
- MQTT Tests
- Security Tests
- Integration Tests
- Smoke Tests
- Report Generation - Merged test results
- Artifact Upload - Test reports and logs
The pipeline automatically runs on:
- Push to
mainordevelop - Pull requests
- Manual trigger (
workflow_dispatch)
Edit config/environments/dev.yaml or config/environments/ci.yaml:
api:
base_url: http://localhost:8000
timeout: 30
mqtt:
broker_host: localhost
broker_port: 8883
ca_cert: certs/ca/ca.crt
client_cert: certs/clients/test-client.crt
client_key: certs/clients/test-client.key
auth:
admin_username: admin@smarthome.local
jwt_secret: your-secret-key# Development
python3 cli.py run --env dev
# CI/CD
python3 cli.py run --env ci-
Create test file in appropriate directory:
*** Settings *** Resource ../../resources/common.robot *** Test Cases *** My New Test [Tags] smoke # Test steps here
-
Run the test:
python3 cli.py run --tags smoke
Add keywords to resources/*.robot files:
*** Keywords ***
My Custom Keyword
[Arguments] ${arg1} ${arg2}
Log Processing ${arg1} and ${arg2}
# ImplementationModify libraries in libraries/*/ and use the @keyword decorator:
from robot.api.deco import keyword
@keyword("My Custom Keyword")
def my_custom_keyword(self, param):
# Implementation
passCertificate errors:
# Regenerate certificates
python3 cli.py setupMQTT connection fails:
# Check broker is running
docker-compose ps mosquitto
# Check logs
docker-compose logs mosquittoAPI not responding:
# Check API health
curl http://localhost:8000/health
# Restart services
docker-compose restart mock-apiRun tests with verbose logging:
python3 cli.py run --suite api --verboseView detailed logs:
# Robot Framework logs
cat reports/*/log.html
# MQTT broker logs
docker-compose logs -f mosquitto
# API logs
docker-compose logs -f mock-apiThe framework tracks:
- API response times
- MQTT message latency
- Message throughput
- Connection stability
- Test execution time
Access metrics via keywords:
${api_metrics}= Get API Metrics
${mqtt_metrics}= Get MQTT Metrics- Always run smoke tests before committing
- Use tags for test organization
- Generate fresh certificates for security tests
- Clean up resources in test teardown
- Use parallel execution for faster CI
- Monitor performance metrics for regressions
- Keep certificates secure (don't commit private keys in production)
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
- Robot Framework community
- Eclipse Mosquitto project
- Paho MQTT Python client
- Flask web framework
For questions or support:
- Create an issue on GitHub
- Email: pauli@manki.fi
Built with ❤️ for robust IoT testing