run_specific_tests.sh picks up tests from file generated by run_all_tests.sh

This commit is contained in:
simonredfern 2025-12-31 04:40:19 +01:00
parent 18f8b8f451
commit 2957488a68
2 changed files with 64 additions and 8 deletions

View File

@ -89,6 +89,7 @@ trap cleanup_on_exit EXIT INT TERM
LOG_DIR="test-results" LOG_DIR="test-results"
DETAIL_LOG="${LOG_DIR}/last_run.log" # Full Maven output DETAIL_LOG="${LOG_DIR}/last_run.log" # Full Maven output
SUMMARY_LOG="${LOG_DIR}/last_run_summary.log" # Summary only SUMMARY_LOG="${LOG_DIR}/last_run_summary.log" # Summary only
FAILED_TESTS_FILE="${LOG_DIR}/failed_tests.txt" # Failed test list for run_specific_tests.sh
mkdir -p "${LOG_DIR}" mkdir -p "${LOG_DIR}"
@ -301,6 +302,40 @@ generate_summary() {
# Look for ScalaTest failure markers, not application ERROR logs # Look for ScalaTest failure markers, not application ERROR logs
grep -E "\*\*\* FAILED \*\*\*|\*\*\* RUN ABORTED \*\*\*" "${detail_log}" | head -50 >> "${summary_log}" grep -E "\*\*\* FAILED \*\*\*|\*\*\* RUN ABORTED \*\*\*" "${detail_log}" | head -50 >> "${summary_log}"
log_message "" log_message ""
# Extract failed test class names and save to file for run_specific_tests.sh
# Look backwards from "*** FAILED ***" to find the test class name
# ScalaTest prints: "TestClassName:" before scenarios
> "${FAILED_TESTS_FILE}" # Clear/create file
echo "# Failed test classes from last run" >> "${FAILED_TESTS_FILE}"
echo "# Auto-generated by run_all_tests.sh - you can edit this file manually" >> "${FAILED_TESTS_FILE}"
echo "#" >> "${FAILED_TESTS_FILE}"
echo "# Format: One test class per line with full package path" >> "${FAILED_TESTS_FILE}"
echo "# Example: code.api.v6_0_0.RateLimitsTest" >> "${FAILED_TESTS_FILE}"
echo "#" >> "${FAILED_TESTS_FILE}"
echo "# Usage: ./run_specific_tests.sh will read this file and run only these tests" >> "${FAILED_TESTS_FILE}"
echo "#" >> "${FAILED_TESTS_FILE}"
echo "# Lines starting with # are ignored (comments)" >> "${FAILED_TESTS_FILE}"
echo "" >> "${FAILED_TESTS_FILE}"
# Extract test class names from failures
grep -B 20 "\*\*\* FAILED \*\*\*" "${detail_log}" | \
grep -oP "^[A-Z][a-zA-Z0-9_]+(?=:)" | \
sort -u | \
while read test_class; do
# Try to find package by searching for the class in test files
package=$(find obp-api/src/test/scala -name "${test_class}.scala" | \
sed 's|obp-api/src/test/scala/||' | \
sed 's|/|.|g' | \
sed 's|.scala$||' | \
head -1)
if [ -n "$package" ]; then
echo "$package" >> "${FAILED_TESTS_FILE}"
fi
done
log_message "Failed test classes saved to: ${FAILED_TESTS_FILE}"
log_message ""
elif [ "${ERRORS}" != "0" ] && [ "${ERRORS}" != "UNKNOWN" ]; then elif [ "${ERRORS}" != "0" ] && [ "${ERRORS}" != "UNKNOWN" ]; then
log_message "Test Errors:" log_message "Test Errors:"
grep -E "\*\*\* FAILED \*\*\*|\*\*\* RUN ABORTED \*\*\*" "${detail_log}" | head -50 >> "${summary_log}" grep -E "\*\*\* FAILED \*\*\*|\*\*\* RUN ABORTED \*\*\*" "${detail_log}" | head -50 >> "${summary_log}"
@ -554,6 +589,9 @@ log_message ""
log_message "Logs saved to:" log_message "Logs saved to:"
log_message " ${DETAIL_LOG}" log_message " ${DETAIL_LOG}"
log_message " ${SUMMARY_LOG}" log_message " ${SUMMARY_LOG}"
if [ -f "${FAILED_TESTS_FILE}" ]; then
log_message " ${FAILED_TESTS_FILE}"
fi
echo "" echo ""
exit ${EXIT_CODE} exit ${EXIT_CODE}

View File

@ -4,23 +4,26 @@
# Run Specific Tests Script # Run Specific Tests Script
# #
# Simple script to run specific test classes for fast iteration. # Simple script to run specific test classes for fast iteration.
# Edit SPECIFIC_TESTS array below with the test class names you want to run. # Reads test classes from test-results/failed_tests.txt (auto-generated by run_all_tests.sh)
# or you can edit the file manually.
# #
# Usage: # Usage:
# ./run_specific_tests.sh # ./run_specific_tests.sh
# #
# Configuration: # Configuration:
# Update SPECIFIC_TESTS array with FULL PACKAGE PATH (required for ScalaTest) # Option 1: Edit test-results/failed_tests.txt (recommended)
# Option 2: Edit SPECIFIC_TESTS array in this script
#
# File format (test-results/failed_tests.txt):
# One test class per line with full package path
# Lines starting with # are comments
# Example: code.api.v6_0_0.RateLimitsTest
# #
# IMPORTANT: ScalaTest requires full package path! # IMPORTANT: ScalaTest requires full package path!
# - Must include: code.api.vX_X_X.TestClassName # - Must include: code.api.vX_X_X.TestClassName
# - Do NOT use just "TestClassName" # - Do NOT use just "TestClassName"
# - Do NOT include .scala extension # - Do NOT include .scala extension
# #
# Examples:
# SPECIFIC_TESTS=("code.api.v6_0_0.RateLimitsTest")
# SPECIFIC_TESTS=("code.api.v6_0_0.RateLimitsTest" "code.api.v6_0_0.ConsumerTest")
#
# How to find package path: # How to find package path:
# 1. Find test file: obp-api/src/test/scala/code/api/v6_0_0/RateLimitsTest.scala # 1. Find test file: obp-api/src/test/scala/code/api/v6_0_0/RateLimitsTest.scala
# 2. Package path: code.api.v6_0_0.RateLimitsTest # 2. Package path: code.api.v6_0_0.RateLimitsTest
@ -37,10 +40,13 @@
set -e set -e
################################################################################ ################################################################################
# CONFIGURATION - Edit this! # CONFIGURATION
################################################################################ ################################################################################
FAILED_TESTS_FILE="test-results/failed_tests.txt"
# Test class names - MUST include full package path for ScalaTest! # Test class names - MUST include full package path for ScalaTest!
# This will be overridden if test-results/failed_tests.txt exists
# Format: "code.api.vX_X_X.TestClassName" # Format: "code.api.vX_X_X.TestClassName"
# Example: "code.api.v6_0_0.RateLimitsTest" # Example: "code.api.v6_0_0.RateLimitsTest"
SPECIFIC_TESTS=( SPECIFIC_TESTS=(
@ -57,10 +63,22 @@ SUMMARY_LOG="${LOG_DIR}/last_specific_run_summary.log"
mkdir -p "${LOG_DIR}" mkdir -p "${LOG_DIR}"
# Read tests from file if it exists, otherwise use SPECIFIC_TESTS array
if [ -f "${FAILED_TESTS_FILE}" ]; then
echo "Reading test classes from: ${FAILED_TESTS_FILE}"
# Read non-empty, non-comment lines from file into array
mapfile -t SPECIFIC_TESTS < <(grep -v '^\s*#' "${FAILED_TESTS_FILE}" | grep -v '^\s*$')
echo "Loaded ${#SPECIFIC_TESTS[@]} test(s) from file"
echo ""
fi
# Check if tests are configured # Check if tests are configured
if [ ${#SPECIFIC_TESTS[@]} -eq 0 ]; then if [ ${#SPECIFIC_TESTS[@]} -eq 0 ]; then
echo "ERROR: No tests configured!" echo "ERROR: No tests configured!"
echo "Edit this script and add test names to SPECIFIC_TESTS array" echo "Either:"
echo " 1. Run ./run_all_tests.sh first to generate ${FAILED_TESTS_FILE}"
echo " 2. Create ${FAILED_TESTS_FILE} manually with test class names"
echo " 3. Edit this script and add test names to SPECIFIC_TESTS array"
exit 1 exit 1
fi fi