DEV Community

Er. Bhupendra
Er. Bhupendra

Posted on

springboot and junit

Here is the Ultimate 100-Question Master List for Spring Boot & JUnit.

This list combines Development (Spring Boot) and Quality Assurance (JUnit/Mockito). If you master these, you are technically over-prepared for any 0–3 year experience interview in 2025.


πŸš€ Part 1: Spring Boot Core & Architecture

# Question Key Concept
1 What is Spring Boot? Opinionated view of Spring; "Convention over Configuration".
2 Difference: Spring Framework vs. Spring Boot? Spring = Engine; Boot = Car (Pre-configured, Embedded Server).
3 What are the main advantages of Spring Boot? Rapid dev, No XML, Embedded Server, Production ready.
4 What is Auto-Configuration? Boot scans jars on classpath & configures beans automatically.
5 What does @SpringBootApplication do? Combines @Configuration, @EnableAutoConfiguration, @ComponentScan.
6 What is a "Starter" dependency? A bundle of dependencies (e.g., starter-web has Tomcat + MVC).
7 How does dependency management work? managed by spring-boot-dependencies (BOM) to match versions.
8 What is the default embedded server? Apache Tomcat.
9 Can we change the embedded server? Yes (exclude Tomcat, add Jetty or Undertow).
10 What is SpringApplication.run()? Bootstraps the app, starts context, starts Tomcat.
11 JAR vs WAR in Spring Boot? JAR = Embedded server (Self-contained). WAR = External server.
12 Why is Spring Boot good for Microservices? Lightweight, independent deployment, cloud-native ready.
13 What is Spring Initializr? Web tool (start.spring.io) to generate project structure.
14 What is the Spring Boot CLI? Command line tool to run Groovy scripts (rarely used now).
15 What is the default Logging framework? Logback (via SLF4J).

βš™οΈ Part 2: Configuration, DI & Beans

# Question Key Concept
16 What is application.properties? Central configuration file (Port, DB URL, etc.).
17 application.properties vs application.yml? YML is hierarchical/structured; Properties is flat (key=value).
18 What is Dependency Injection (DI)? Spring provides objects (beans) to your class; you don't use new.
19 What is Inversion of Control (IoC)? Transferring control of object creation from programmer to Spring.
20 Constructor vs Setter vs Field Injection? Constructor is best (easier for testing, ensures immutability).
21 What does @Autowired do? Tells Spring to inject a bean here.
22 @Component vs @Service vs @Repository? All are beans. Service = Biz Logic, Repository = DB Exception translation.
23 Difference: @Controller vs @RestController? Controller = Returns View/HTML. RestController = Returns Data/JSON.
24 What is the @Bean annotation? Used in @Configuration classes to manually declare a bean.
25 What is the default Scope of a Bean? Singleton (One instance per application).
26 What is Prototype Scope? New instance created every time it is requested.
27 What is @Lazy initialization? Bean is created only when first requested, not at startup.
28 What is @Value? Injects property values (strings/numbers) from config file.
29 What is @ConfigurationProperties? Type-safe binding of properties to a Java class (better than @Value).
30 What are Profiles (dev, prod)? Separate configs for environments (application-dev.properties).
31 How to activate a Profile? spring.profiles.active=dev.
32 What is @PostConstruct? Runs logic immediately after bean creation/DI is done.
33 What is @PreDestroy? Runs logic just before the bean is removed (cleanup).
34 What is a Circular Dependency? A needs B, B needs A. Fix using @Lazy.
35 What is Spring Boot DevTools? Enables hot-swap/live-reload during development.

🌐 Part 3: Web (REST API) & Exception Handling

# Question Key Concept
36 Dependency for REST API? spring-boot-starter-web.
37 What does @RequestMapping do? Maps HTTP requests (URL) to Handler methods.
38 Methods: Get, Post, Put, Delete? Get=Read, Post=Create, Put=Update, Delete=Remove.
39 @RequestParam vs @PathVariable? PathVar = /user/1 (Clean URL). ReqParam = /user?id=1 (Filter/Sort).
40 What is @RequestBody? Maps JSON body to Java Object (Deserialization).
41 What is ResponseEntity? Wrapper to customize HTTP Status, Headers, and Body.
42 Return specific Status Code (e.g. 201)? return new ResponseEntity<>(HttpStatus.CREATED);.
43 What is a DTO? Why use it? Data Transfer Object. Decouples DB Entity from API response.
44 How to handle Exceptions Globally? Use @ControllerAdvice + @ExceptionHandler.
45 @ExceptionHandler vs @ControllerAdvice? ExceptionHandler = Local (one controller). Advice = Global.
46 What is Swagger/OpenAPI? Library (springdoc-openapi) to auto-generate API docs & UI.
47 Difference: put vs patch? Put = Replace entire object. Patch = Partial update.
48 What is Serialization? Converting Java Object -> JSON (Jackson library does this).
49 How to validate input? Use @Valid and Javax annotations (@NotNull, @Size).
50 How to consume external APIs? RestTemplate (Legacy) or WebClient (Modern).

πŸ’Ύ Part 4: Data (JPA, DB & Transactions)

# Question Key Concept
51 What is Spring Data JPA? Layer on top of Hibernate to reduce boilerplate code.
52 What is JpaRepository? Interface providing CRUD methods (save, findAll) out of the box.
53 What is the H2 Database? In-memory DB. Data is lost when app stops. Good for testing.
54 spring.jpa.hibernate.ddl-auto? create, update, validate, none (Schema management).
55 What are Derived Query Methods? findByName(String name) -> Auto-generates SQL.
56 What is @Query? Used to write custom SQL or JPQL queries.
57 What does @Transactional do? Ensures atomicity. If error occurs, rolls back all DB changes.
58 What is Lazy Loading in JPA? Associated data (e.g., Orders of a User) loads only when accessed.
59 N+1 Problem in Hibernate? 1 Query for Parent, N queries for Children. Fix using JOIN FETCH.
60 How to configure DB password? In application.properties (spring.datasource.password).

πŸ›‘οΈ Part 5: Advanced (Security, Ops, AOP)

# Question Key Concept
61 What is Spring Boot Actuator? Production monitoring endpoints (/health, /metrics, /info).
62 How to enable Actuator? Add spring-boot-starter-actuator.
63 Basic Security setup? Add starter-security. Default: Basic Auth (User + Generated Pwd).
64 Authentication vs Authorization? Auth = Who are you? (Login). AuthZ = What can you do? (Roles).
65 What is AOP? Aspect-Oriented Programming. Separates cross-cutting concerns (Logs).
66 AOP: Advice vs Pointcut? Advice = What to do. Pointcut = Where to apply it.
67 How to schedule tasks? @EnableScheduling + @Scheduled(cron = "...").
68 How to run Async methods? @EnableAsync + @Async (Runs in separate thread).
69 What is Project Lombok? Auto-generates Getters/Setters/Constructors to reduce code.
70 CORS in Spring Boot? Cross-Origin Resource Sharing. Configured via @CrossOrigin.

πŸ§ͺ Part 6: JUnit 5 (Testing Core)

# Question Key Concept
71 What is JUnit 5 (Jupiter)? The standard testing framework for Java.
72 Why Unit Test? Catch bugs early, ensure code quality, safe refactoring.
73 @Test annotation? Marks a method as a test case.
74 @BeforeEach vs @BeforeAll? Each = Before every test method. All = Once per class (Static).
75 @AfterEach vs @AfterAll? Cleanup methods (after every test vs once at end).
76 How to ignore a test? @Disabled.
77 What is @DisplayName? Custom name for test in reports (e.g., "Should return 404").
78 assertEquals vs assertSame? Equals = Checks value (.equals()). Same = Checks object reference.
79 How to test Exceptions? assertThrows(Exception.class, () -> service.method()).
80 What is @ParameterizedTest? Run same test multiple times with different inputs (@ValueSource).
81 What is assertTimeout? Fails if test takes longer than X seconds.
82 Difference: Failure vs Error? Failure = Assertion failed. Error = Exception/Crash in code.
83 What is the AAA Pattern? Arrange (Setup), Act (Call method), Assert (Verify result).
84 What is Code Coverage? Percentage of code lines executed by tests (Aim for >80%).
85 TDD (Test Driven Development)? Write Test first (Fail) -> Write Code (Pass) -> Refactor.

🦜 Part 7: Mockito & Integration Testing (The Tricky Stuff)

# Question Key Concept
86 Why do we Mock? To isolate the unit. Don't hit real DB or API in Unit Tests.
87 @Mock vs @InjectMocks? Mock = Creates fake dependency. InjectMocks = Target class accepting mocks.
88 What is when(...).thenReturn(...)? Stubs behavior: "When repo.findById(1) is called, return User A".
89 How to verify a call? verify(repo, times(1)).save(user).
90 Mocking void methods? Cannot use when. Use doNothing().when(mock).method().
91 What is @Spy? Partial mock. Real object is called unless specific method is stubbed.
92 @SpringBootTest vs @WebMvcTest? SpringBootTest = Full Context (Slow). WebMvcTest = Only Controllers (Fast).
93 @Mock (Mockito) vs @MockBean (Spring)? Use @Mock in Unit tests. Use @MockBean to replace bean in Spring Context.
94 What is MockMvc? Tool to simulate HTTP requests in Controller tests without starting Server.
95 How to test Repository Layer? @DataJpaTest (Uses in-memory H2 DB automatically).
96 What is ArgumentCaptor? Captures arguments passed to a mock to assert their values later.
97 How to test private methods? Don't. Test the public method calling it. Or use Reflection (bad practice).
98 Mocking Static Methods? Use MockedStatic (Available in Mockito 3.4+).
99 What are Testcontainers? Docker-based testing. Spins up real DB (Postgres) for integration tests.
100 Testing JSON responses? Use JsonPath ($.id) to verify specific fields in JSON string.

Top comments (0)