spring-test-slices: Spring Boot 4.1.2 test slices lab (@WebMvcTest, @JsonTest, @RestClientTest, @DataJpaTest vs @SpringBootTest)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7Jbw5CxUQ13D7gn25
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in spring-test-slices/output/.
|
||||
# Needs JDK 25 and Maven on the PATH. Takes about a minute.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
OUT=output
|
||||
# keep transcripts free of JVM launcher noise that varies per machine
|
||||
filter() { grep -vE '^(Picked up JAVA_TOOL_OPTIONS|WARNING: )' || true; }
|
||||
|
||||
rm -f "$OUT"/*.txt
|
||||
mkdir -p "$OUT"
|
||||
|
||||
# 1. the whole suite: every test writes its own transcript to output/ and asserts the same facts
|
||||
mvn -B -q clean test 2>&1 | filter | grep -E 'Tests run:|BUILD|ERROR' || true
|
||||
|
||||
# 2. which test jars does spring-boot-starter-test alone bring in?
|
||||
./scripts/starter-test-only.sh
|
||||
|
||||
# 3. startup time of each context, one test class per JVM so nothing is cached.
|
||||
# Spring Boot logs "Started <TestClass> in N seconds" for every context it builds.
|
||||
# Timings vary by machine and by run: read them as indicative, not as a result.
|
||||
{
|
||||
echo "Context startup time per test class (one class per mvn run; indicative, varies between runs)"
|
||||
echo
|
||||
for cls in JsonSliceTest RestClientSliceTest WebMvcSliceTest DataJpaSliceTest FullContextTest; do
|
||||
mvn -B test -Dtest="$cls" 2>&1 | grep -oE "Started $cls in [0-9.]+ seconds" | head -1
|
||||
done
|
||||
} > "$OUT/30-startup-times.txt"
|
||||
|
||||
echo "done: $(ls "$OUT" | wc -l) files in $OUT/"
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
# Which Boot test jars does spring-boot-starter-test alone bring in?
|
||||
# Resolves a throwaway project with the three production starters and ONLY spring-boot-starter-test,
|
||||
# then lists every spring-boot jar with "test" in its name. Writes output/12-starter-test-only-jars.txt.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
BOOT="$(sed -n '/<artifactId>spring-boot-starter-parent<\/artifactId>/{n;s/.*<version>\(.*\)<\/version>.*/\1/p}' pom.xml)"
|
||||
TMP=target/starter-test-only
|
||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||
cat > "$TMP/pom.xml" <<POM
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"><modelVersion>4.0.0</modelVersion>
|
||||
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>${BOOT}</version><relativePath/></parent>
|
||||
<groupId>probe</groupId><artifactId>starter-test-only</artifactId><version>1</version>
|
||||
<dependencies>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webmvc</artifactId></dependency>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-restclient</artifactId></dependency>
|
||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
POM
|
||||
mvn -B -q -f "$TMP/pom.xml" dependency:build-classpath -Dmdep.outputFile=cp.txt > /dev/null 2>&1
|
||||
{
|
||||
echo "Spring Boot ${BOOT}: webmvc + data-jpa + restclient starters, and only spring-boot-starter-test for tests"
|
||||
echo "spring-boot jars with 'test' in the name on that classpath:"
|
||||
tr ':' '\n' < "$TMP/cp.txt" | sed 's#.*/##' | grep -E '^spring-boot.*test' | sed 's/^/ /'
|
||||
} > output/12-starter-test-only-jars.txt
|
||||
Reference in New Issue
Block a user