-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·102 lines (87 loc) · 3.05 KB
/
run-tests.sh
File metadata and controls
executable file
·102 lines (87 loc) · 3.05 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
#!/bin/bash
# Spring Boot Docker Test Runner
# Usage: ./run-tests.sh [option]
# Options:
# fast - Run tests using Docker build (fastest)
# compose - Run tests using docker-compose
# coverage - Run tests with coverage report
# watch - Run tests in watch mode (development)
# clean - Clean up test containers and volumes
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[TEST RUNNER]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Default option
OPTION=${1:-fast}
case $OPTION in
"fast")
print_status "Running tests using Docker build (fastest method)..."
docker build --target test -t spring-boot-demo-test .
print_success "Tests completed successfully!"
;;
"compose")
print_status "Running tests using docker-compose..."
docker-compose -f docker-compose.test.yml up --build test
print_success "Tests completed successfully!"
;;
"coverage")
print_status "Running tests with coverage report..."
docker-compose -f docker-compose.test.yml up --build test-with-coverage
print_success "Tests with coverage completed! Check target/site/jacoco/index.html"
;;
"watch")
print_status "Running tests in watch mode..."
print_warning "Press Ctrl+C to stop watching"
docker-compose -f docker-compose.test.yml up --build test
while true; do
print_status "Watching for file changes... (Press Ctrl+C to exit)"
sleep 5
docker-compose -f docker-compose.test.yml up --build test
done
;;
"clean")
print_status "Cleaning up test containers and volumes..."
docker-compose -f docker-compose.test.yml down -v --remove-orphans
docker rmi spring-boot-demo-test 2>/dev/null || true
print_success "Cleanup completed!"
;;
"help"|"-h"|"--help")
echo "Spring Boot Docker Test Runner"
echo ""
echo "Usage: ./run-tests.sh [option]"
echo ""
echo "Options:"
echo " fast Run tests using Docker build (fastest, default)"
echo " compose Run tests using docker-compose"
echo " coverage Run tests with coverage report"
echo " watch Run tests in watch mode (development)"
echo " clean Clean up test containers and volumes"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " ./run-tests.sh # Run tests (fast mode)"
echo " ./run-tests.sh coverage # Run with coverage"
echo " ./run-tests.sh clean # Clean up"
;;
*)
print_error "Unknown option: $OPTION"
print_status "Use './run-tests.sh help' to see available options"
exit 1
;;
esac