IBM Test Accelerator for Z Unit Test CLI Examples
This page provides practical examples for using the IBM® Test Accelerator for Z unit test CLI in various scenarios.
Basic Examples
Basic execution
Run all tests in a directory with required parameters:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB
Using command alias
Use the shorter ut alias instead of unittest:
taz ut run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB
Specifying Multiple User Libraries
Method 1: Multiple flags
Specify multiple user libraries using repeated --userLibrary flags:
taz unittest run tests/PROG1 --procLib CUST.PROCLIB --userLibrary LIB1 --userLibrary LIB2
Method 2: Comma-separated values
Specify multiple user libraries as comma-separated values:
taz unittest run tests/PROG1 --procLib CUST.PROCLIB --userLibrary LIB1,LIB2,LIB3
Customizing Execution
With custom timeout
Increase the job timeout to 5 minutes (300 seconds):
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --timeout 300
With custom root directory
Specify a different root directory for resolving test case and test data files:
taz unittest run tests --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --rootDirectory /path/to/project
With custom output directory
Specify a custom location for test results:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --output /path/to/results
Output Control
Verbose mode for debugging
Enable detailed logging to troubleshoot issues:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --verbose
Quiet mode for CI/CD pipelines
Suppress output except for errors (useful for automation):
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --quiet
JSON output for automation
Output results in JSON format for parsing by CI/CD tools:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --json
Disable colored output
Disable ANSI colors in output:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --no-color
With Code Coverage
With code coverage running on the same system on port 8009:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --no-color -codeCoverage locahost:8009
With Code Coverage using an IPV6 address
With code coverage running on the same system on port 8009:
taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB --no-color -codeCoverage [::1]:8009
Validation Examples
Validate test files before running
Check test case files (*.ztest) and test data files (*.zdata) for syntax errors:
taz unittest validate tests/PROG1
Validate with verbose output
Get detailed validation information:
taz unittest validate tests/PROG1 --verbose
CI/CD Integration Examples
Jenkins Pipeline
Example Jenkinsfile stage for running TAZ unit tests:
stage('Run Unit Tests') {
steps {
sh '''
taz unittest run tests \
--procLib SYS1.PROCLIB \
--userLibrary USER.LOADLIB \
--no-color \
--quiet \
--json
'''
}
post {
always {
junit '.taz-edt-results/*.xml'
}
}
}
Advanced Examples
Combining multiple options
Run tests with multiple customizations:
taz unittest run tests/PROG1 \
--procLib CUST.V70.PROCLIB \
--userLibrary LIB1,LIB2,LIB3 \
--timeout 300 \
--rootDirectory /u/myuser/project \
--output /u/myuser/results \
--json \
--verbose
Using environment variables
Disable colors using the NO_COLOR environment variable:
export NO_COLOR=1; taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB
Force colors even when piping output:
export FORCE_COLOR=1; taz unittest run tests/PROG1 --procLib SYS1.PROCLIB --userLibrary USER.LOADLIB | tee output.log
Shell Script Integration
Basic shell script
Example shell script for running tests:
#!/bin/bash# Configuration
PROCLIB="SYS1.PROCLIB"
LOADLIB="USER.LOADLIB"
TEST_DIR="tests"# Run tests
taz unittest run "$TEST_DIR" \
--procLib "$PROCLIB" \
--userLibrary "$LOADLIB" \
--quiet
# Check exit codeif [ $? -eq 0 ]; thenecho"All tests passed!"exit 0
elseecho"Tests failed!"exit 1
fi
Script with error handling
Example script with comprehensive error handling:
#!/bin/bashset -e # Exit on error# Configuration
PROCLIB="${PROCLIB:-SYS1.PROCLIB}"
LOADLIB="${LOADLIB:-USER.LOADLIB}"
TEST_DIR="${TEST_DIR:-tests}"
TIMEOUT="${TIMEOUT:-120}"# Validate test files firstecho"Validating test files..."if ! taz unittest validate "$TEST_DIR"; thenecho"ERROR: Test validation failed"exit 1
fi# Run testsecho"Running tests..."
taz unittest run "$TEST_DIR" \
--procLib "$PROCLIB" \
--userLibrary "$LOADLIB" \
--timeout"$TIMEOUT" \
--json \
--output results
# Check results
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; thenecho"SUCCESS: All tests passed"elif [ $EXIT_CODE -eq 1 ]; thenecho"ERROR: User error or validation failure"elif [ $EXIT_CODE -eq 2 ]; thenecho"ERROR: Execution error"fiexit$EXIT_CODE
Troubleshooting Examples
Debug a failing test
Run with verbose output to see detailed information:
taz unittest run tests/FAILING_TEST \
--procLib SYS1.PROCLIB \
--userLibrary USER.LOADLIB \
--verbose \
--no-color > debug.log 2>&1
Test with increased timeout
If tests are timing out, increase the timeout value:
taz unittest run tests/SLOW_TEST \
--procLib SYS1.PROCLIB \
--userLibrary USER.LOADLIB \
--timeout 600
Validate specific test directory
Check only a specific subdirectory for issues:
taz unittest validate tests/PROG1/unit --verbose
Related Documentation