-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
135 lines (115 loc) · 3.13 KB
/
run-tests.sh
File metadata and controls
135 lines (115 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# API Test Framework Runner Script
# Usage: ./run-tests.sh [options]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Default values
THREAD_COUNT=1
TEST_GROUP=""
ENVIRONMENT="local"
GENERATE_REPORT=false
# Function to print colored output
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Function to show usage
show_usage() {
cat << EOF
Usage: ./run-tests.sh [OPTIONS]
Options:
-t, --threads <number> Number of parallel threads (default: 1)
-g, --group <name> Test group: users, products, smoke, or empty for all
-e, --env <environment> Environment: local, ci (default: local)
-r, --report Generate and open Allure report after tests
-h, --help Show this help message
Examples:
./run-tests.sh # Run all tests with 1 thread
./run-tests.sh -t 4 # Run all tests with 4 threads
./run-tests.sh -g users -t 2 # Run users tests with 2 threads
./run-tests.sh -g products -t 2 -r # Run products tests and generate report
./run-tests.sh --threads 4 --report # Run all tests with 4 threads and report
EOF
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--threads)
THREAD_COUNT="$2"
shift 2
;;
-g|--group)
TEST_GROUP="$2"
shift 2
;;
-e|--env)
ENVIRONMENT="$2"
shift 2
;;
-r|--report)
GENERATE_REPORT=true
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Validate thread count
if ! [[ "$THREAD_COUNT" =~ ^[0-9]+$ ]] || [ "$THREAD_COUNT" -lt 1 ]; then
print_error "Thread count must be a positive integer"
exit 1
fi
# Build Maven command
MVN_CMD="mvn clean test"
# Add environment
MVN_CMD="$MVN_CMD -Denv=$ENVIRONMENT"
# Add thread count
MVN_CMD="$MVN_CMD -Dthread.count=$THREAD_COUNT"
# Add test group if specified
if [ -n "$TEST_GROUP" ]; then
case $TEST_GROUP in
users|products|smoke)
MVN_CMD="$MVN_CMD -P$TEST_GROUP"
print_info "Running $TEST_GROUP tests"
;;
*)
print_error "Invalid test group: $TEST_GROUP"
print_warning "Valid groups: users, products, smoke"
exit 1
;;
esac
else
print_info "Running all tests"
fi
print_info "Environment: $ENVIRONMENT"
print_info "Thread count: $THREAD_COUNT"
print_info "Command: $MVN_CMD"
echo ""
# Run tests
if eval $MVN_CMD; then
print_info "Tests completed successfully!"
# Generate report if requested
if [ "$GENERATE_REPORT" = true ]; then
print_info "Generating Allure report..."
mvn allure:serve
fi
else
print_error "Tests failed!"
exit 1
fi