Skip to content

TDD with Java and SpringBoot

Somkiat Puisungnoen edited this page May 19, 2026 · 1 revision

Post-Test of TDD with Java and SpringBoot

1. In the TDD Life Cycle (Red-Green-Refactor), what is the primary goal of the 'Green' phase ?

  • A. To write the most elegant and optimized code possible
  • B. To write just enough code to make the failing test pass
  • C. To identify and fix bugs in the production environment
  • D. To design the database schema

2. Following the 'GUT' (Good Unit Test) structure, what happens during the 'Assert' stage ?

  • A. The database connection is closed
  • B. The actual result is compared against the expected outcome
  • C. The method under test is executed.
  • D. The test environment is initialized

3. According to the FIRST principles of testing, what does 'Self-Validating' mean ?

  • A. The test should run automatically on a schedule
  • B. The developer must manually check the logs to see if the test passed
  • C. The test code should be able to fix the production code automatically
  • D. The test should have a clear pass/fail output without human interpretation

4. What is the main difference between a 'Stub' and a 'Mock' in Test Doubles ?

  • A. Mocks are always faster than Stubs
  • B. Stubs provide canned answers; Mocks verify that specific calls were made (behavior verification)
  • C. Stubs verify behavior; Mocks provide state
  • D. Stubs are used in Spring Boot; Mocks are used in Vanilla Java

5. In Spring Boot, what is the role of Dependency Injection (DI) ?

  • A. It allows a class to receive its dependencies from an external source (the Spring Container)
  • B. It is a tool used exclusively for connecting to SQL databases
  • C. It prevents the use of interfaces
  • D. It manually creates every object using the 'new' keyword

6. When testing the Controller layer, what does '@WebMvcTest' provide ?

  • A. A full server start-up with a real database connection
  • B. A slice of the Spring Context focusing only on MVC components (Controllers, Filters, etc.)
  • C. Automatic generation of documentation for the API
  • D. A way to test the Repository layer directly

7. Why is the Service Layer considered the 'Business Process' layer ?

  • A. Because it handles HTTP status codes
  • B. Because it writes raw SQL queries
  • C. Because it contains the core logic, rules, and transaction management of the application
  • D. Because it is the only layer that uses the @Bean annotation

8. In the Repository Layer, what does '@DataJpaTest' automatically do to transactions after a test method finishes ?

  • A. Rolls back the transaction
  • B. Sends an email notification of the test result
  • C. Commits the changes to the database permanently
  • D. Deletes the entire database schema

9. What is the benefit of using 'Data-Driven Tests' (@ParameterizedTest) in JUnit ?

  • A. It is required for every Spring Boot project
  • B. It allows running the same test logic with different inputs and expected outputs to reduce code duplication
  • C. It automatically fixes syntax errors in the production code
  • D. It makes the test code 10 times faster

10. Which Test Double is an 'actual implementation' that is simplified (e.g., an In-Memory Database) ?

  • A. Mock
  • B. Spy
  • C. Dummy
  • D. Fake

Clone this wiki locally