Spring-boot读书笔记一关于test method name&folder build

The test method name is always very long due to:

The test method name such as "givenDatasourceAvailableWhenAccessDetailsThenExpectDetails" follows the BDD (Behavior-Driven Development) naming convention:

  • Given - precondition: "Datasource Available"
  • When - action: "Access Details"
  • Then - expected outcome: "Expect Details"

This verbose naming style:

  • Makes tests self-documenting
  • Clearly describes what the test does without reading the code
  • Follows Given-When-Then pattern popular in testing

How test classes in test folder are built:
Maven/Gradle Build Process:

  • Source Compilation: src/main/java compiled first
  • Test Compilation: src/test/java compiled against main classes + test dependencies
  • Test Execution: Tests run during test phase
  • Test Dependencies: JUnit, Spring Test, AssertJ available only during testing

Directory Structure:

src/
├── main/java/          # Production code
└── test/java/          # Test code (mirrors main structure)

Build Tools Handle:

  • Classpath separation: Test code can access main code, not vice versa
  • Dependency scoping: Test dependencies (JUnit, etc.) only available during testing
  • Test discovery: Automatically finds classes ending with Test or Tests
  • Spring Boot Test: @SpringBootTest loads application context for integration testing

The test folder structure mirrors the main package structure for organization and clarity.

posted @ 2026-01-01 18:41  kkbln  阅读(2)  评论(0)    收藏  举报