Spring Boot 06: what tests prove, from debugging to JAR and WAR
What should you trust more after mvn test passes? “The entire system works” is too broad. Read the assertions to identify their scope, then ask what remains unverified when startup or deployment changes.
Version note: this series is based on Spring Boot 3.5.16 because it targets JBoss EAP 8.1. Spring now offers the newer 4.1. For differences between 3.5 and 4.0, see the Spring Boot 4.0 Migration Guide in the sources.
Identify the environment created by the test
@SpringBootTest(properties = {
"spring.datasource.url=jdbc:h2:mem:bootlab-test;DB_CLOSE_DELAY=-1",
"lab.label=test-label"
})
@AutoConfigureMockMvc
class LabIntegrationTest {
// See the download for injected fields and complete tests.
}@SpringBootTest loads the application context. MockMvc exercises MVC handling inside the process without establishing a real TCP listener. This lab uses its real service and H2 JDBC rather than mocking the entire chain, so it observes writes but does not verify EAP, DB2, or MQ integration.
The Spring Boot 3.5 testing page states: “By default, @SpringBootTest does not start the server but instead sets up a mock environment for testing web endpoints.” The webEnvironment attribute decides whether a real port opens. It has four values.
| Value | Documented behavior | This lab |
|---|---|---|
| MOCK (default) | Loads a web context with a mock web environment; no embedded server starts | Used, with @AutoConfigureMockMvc |
| RANDOM_PORT | Starts the embedded server on a random port | Not used; switch only to test real TCP |
| DEFINED_PORT | Starts the embedded server on the configured port, or 8080 | Not used |
| NONE | Loads a context through SpringApplication with no web environment | Not used |
If a test class is @Transactional, the docs say each test method rolls back by default. RANDOM_PORT and DEFINED_PORT differ: the HTTP client and server run in separate threads and transactions. The sentence is: “Any transaction initiated on the server does not roll back in this case.” Lesson 05 omits @Transactional on its tests to observe the service’s own commit and rollback.
| Approach | Useful evidence | Not established |
|---|---|---|
| Plain unit test | Function or class rules | Spring wiring and transaction advice |
| MVC slice such as @WebMvcTest | Mappings, conversion, validation | Real DB or whole context |
| This context + MockMvc + H2 | Specified HTTP and database effects | Real TCP, DB2, EAP, MQ |
| Packaged JAR + real HTTP | Packaging, startup, embedded server responses | External-container modules and corporate connections |
| Same cases on target environments | Actual integration and old/new behavior | Untested cases and production traffic |
Read assertions, not only test names
mvc.perform(post("/api/tickets")
.contentType("application/json")
.content("{\"title\":\" \"}"))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value("INVALID_REQUEST"));
assertThat(count()).isZero();This excerpt checks the blank-title response and the absence of writes. A rejected response alone would miss accidental persistence. The successful-create test separately checks 201, Location, the returned id, and a follow-up read. Dynamic ids are checked through relationships rather than compared to a fixed value.
The Boot 3.5 docs list MockMvcTester as one integration; it “wraps MockMvc and uses AssertJ.” This lab uses the original MockMvc perform and andExpect style. Both test the same layer; only the assertion style differs.
The lab includes eight integration tests; its VALIDATION.md records execution evidence. A test count is not a coverage percentage or a guarantee for all inputs. Date, permission, or retry changes require corresponding cases rather than relying on the existing eight.
Fix the case and artifact before debugging
Record the input, settings, artifact, response, and data result. Find the earliest boundary that differs from expectations. For startup exceptions, inspect the relevant nested cause rather than treating “context failed” as the diagnosis. Change one cause and repeat the same case to connect the fix to the outcome.
mvn test
mvn package
java -jar target/boot-learning-lab-1.0.0.jar --server.port=8081
# Another terminal:
curl -i http://127.0.0.1:8081/api/pingJAR and WAR change some runtime responsibilities
This project packages an executable JAR whose main starts an embedded server. A traditional WAR is loaded by an external Servlet container; Boot’s documented setup includes a SpringBootServletInitializer subclass, WAR packaging, and provided container dependencies. Renaming the file is insufficient. The download ships the JAR only. The WAR build and embedded-Tomcat start are covered in EAP lesson 08, with its own sample. Deployment to EAP itself is not tested in either series.
Lesson 08: build and inspect a Spring Boot WARWith Boot’s build plugins, a WAR has one more detail. The traditional deployment page says that marking the embedded server dependency as provided produces an executable WAR. Provided dependencies go into a lib-provided directory. It can deploy to a container and also start with java -jar. The Maven plugin docs describe repackage this way: “Repackage existing JAR and WAR archives so that they can be executed from the command line using java -jar.”
This creates a reading trap. A WAR that starts with java -jar proves only the embedded-server path. It does not prove that EAP can load it. For Gradle projects, the docs prefer providedRuntime to compileOnly. One of the reasons: compileOnly dependencies are not on the test classpath, so web integration tests fail.
On EAP, check the listener and context root, then data source/JNDI, transaction manager, logging, and loaded libraries. server.port does not reconfigure EAP’s listener. Boot 3.5’s Servlet requirement is only one condition; vendor support and application modules require separate checks.
Exercise: write a handoff you can explain
Suppose lab.max-title-length changes from 80 to 100. Predict which test fails and whether the table can still store the value. Write the behavior change, configuration location, test adjustment, and remaining integration limits—not just “configuration updated, tests passed.”
Answer: change the 81-character case without removing its purpose
The old 81-character rejection should become acceptance. Check the new boundary at 100 and 101, retaining the no-write assertion on failure. The table’s 200 limit is not reached, but a legacy contract capped at 80 would still change. The learning objective is connecting intent, code, and evidence.
Next-stage EAP/JBoss context: review the migration responsibility mapDownload the complete ticket API lab (ZIP)