This directory contains comprehensive tests for the mail_factory launcher script.
The test suite (test_launcher.sh) validates all aspects of the launcher script including:
-
Help and Version Tests
--helpflag displays usage information--versionflag displays version information
-
Argument Validation Tests
- No arguments provided (should fail)
- Missing configuration file (should fail)
- Invalid JAR path (should fail)
-
Execution Mode Tests
- Dry run mode (
--dry-run) - Debug mode (
--debug) - Normal execution
- Dry run mode (
-
Configuration Tests
- Explicit JAR path (
--jar <path>) - Installation home parameter
- Multiple arguments forwarding
- Relative configuration paths
- Absolute configuration paths
- Explicit JAR path (
-
Environment Variable Tests
JAVA_OPTSforwardingJAVA_HOMEdetectionMAIL_FACTORY_HOMEJAR location override
-
File Validation Tests
- Configuration file existence
- Configuration file extension validation
- JAR file search in multiple locations
# Run all tests
./tests/launcher/test_launcher.sh
# Run with verbose output
bash -x ./tests/launcher/test_launcher.shThe test suite provides colored output:
- 🟢 Green - Tests passed
- 🔴 Red - Tests failed
- 🟡 Yellow - Warnings
- 🔵 Blue - Informational messages
╔════════════════════════════════════════════════════╗
║ Mail Server Factory Launcher Test Suite ║
╚════════════════════════════════════════════════════╝
========================================
TEST: Help flag test
========================================
✓ PASS: Help flag returns exit code 0
✓ PASS: Help output contains USAGE
✓ PASS: Help output contains OPTIONS
✓ PASS: Help output contains EXAMPLES
...
╔════════════════════════════════════════════════════╗
║ Test Summary ║
╚════════════════════════════════════════════════════╝
Total tests run: 45
Tests passed: 45
Tests failed: 0
✅ All tests passed!
The mocks/ directory contains mock files used during testing:
mock-application.jar- Mock JAR file for testing launcher functionality
Tests are executed in an isolated temporary directory (test_tmp/) which is:
- Created at the start of each test run
- Cleaned up after tests complete
- Never committed to version control
The test script uses the following exit codes:
0- All tests passed1- One or more tests failed
To add a new test case:
- Create a new test function following the naming convention
test_<name>() - Use the assertion functions:
assert_exit_code <expected> <actual> <test_name>assert_output_contains <expected> <actual> <test_name>
- Add the test function call to the
main()function - Update this README with the new test description
Example:
test_my_new_feature() {
print_test_header "My new feature test"
local output
output=$("${LAUNCHER}" --my-flag test.json 2>&1)
local exit_code=$?
assert_exit_code 0 ${exit_code} "My feature returns exit code 0"
assert_output_contains "expected text" "${output}" "Output contains expected text"
}These tests should be run:
- Before committing changes to the launcher script
- As part of the CI/CD pipeline
- After any changes to launcher dependencies
Ensure Java 17+ is installed and in your PATH, or set JAVA_HOME.
Build the application first:
./gradlew :Application:installSome tests may behave differently on different platforms (Linux, macOS, etc.). Verify the test expectations match your platform's behavior.
The test suite aims for 100% code coverage of the launcher script, testing:
- All command-line flags
- All error conditions
- All success paths
- Edge cases and boundary conditions
- Environment variable handling
- File system interactions