|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Colors for output |
| 4 | +GREEN='\033[0;32m' |
| 5 | +RED='\033[0;31m' |
| 6 | +NC='\033[0m' # No Color |
| 7 | + |
| 8 | +# Create output directory for reports |
| 9 | +OUTPUT_DIR="test-reports" |
| 10 | +rm -rf "$OUTPUT_DIR" |
| 11 | +mkdir -p "$OUTPUT_DIR" |
| 12 | + |
| 13 | +# First arg is total runs |
| 14 | +if [ "$1" != "" ]; then |
| 15 | + total_runs=$1 |
| 16 | +else |
| 17 | + total_runs=10 |
| 18 | +fi |
| 19 | + |
| 20 | +# Second arg is the gradle task to run |
| 21 | +if [ "$2" != "" ]; then |
| 22 | + gradle_task=$2 |
| 23 | +else |
| 24 | + gradle_task="testDebugUnitTest" |
| 25 | +fi |
| 26 | + |
| 27 | +success_count=0 |
| 28 | +failure_count=0 |
| 29 | + |
| 30 | +echo "Running test $total_runs times with gradle task $gradle_task..." |
| 31 | +echo "------------------------" |
| 32 | +start_time=$(date +%s) |
| 33 | + |
| 34 | +for ((i=1; i<=total_runs; i++)); do |
| 35 | + echo -n "Run #$i: " |
| 36 | + |
| 37 | + # Run the specific test with correct flags |
| 38 | + touch "$OUTPUT_DIR/test-run-$i.txt" |
| 39 | + ./gradlew $gradle_task --rerun-tasks --daemon > "$OUTPUT_DIR/test-run-$i.txt" 2>&1 |
| 40 | + |
| 41 | + if [ $? -eq 0 ]; then |
| 42 | + ((success_count++)) |
| 43 | + echo -e "${GREEN}PASSED${NC}" |
| 44 | + else |
| 45 | + ((failure_count++)) |
| 46 | + echo -e "${RED}FAILED${NC}" |
| 47 | + # Print the output of the test run |
| 48 | + echo "Output of test run $i:" |
| 49 | + cat "$OUTPUT_DIR/test-run-$i.txt" |
| 50 | + # Copy the HTML report with run number |
| 51 | + cp -R "./android/build/reports/tests/" "$OUTPUT_DIR/failure-run-$i/" |
| 52 | + fi |
| 53 | +done |
| 54 | + |
| 55 | +echo "------------------------" |
| 56 | +echo "Execution time: $(($(date +%s) - start_time)) seconds" |
| 57 | +echo "Results:" |
| 58 | +echo "Total runs: $total_runs" |
| 59 | +echo -e "Successes: ${GREEN}$success_count${NC}" |
| 60 | +echo -e "Failures: ${RED}$failure_count${NC}" |
| 61 | +echo "Failure rate: $(( (failure_count * 100) / total_runs ))%" |
| 62 | + |
| 63 | +if [ $failure_count -gt 0 ]; then |
| 64 | + echo "Failure reports saved in $OUTPUT_DIR/" |
| 65 | +fi |
0 commit comments