Testing in Spring Flashcards

1
Q

What is the role of @SpringBootTest in Spring Boot?

A

It is used to create an application context for integration testing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you mock a Spring bean in a unit test?

A

By using @MockBean in conjunction with testing frameworks like Mockito.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between @Mock and @MockBean?

A

@Mock is used with Mockito in unit tests, while @MockBean is used to mock a Spring bean in the application context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you test a Spring MVC controller?

A

Using MockMvc to simulate HTTP requests and assert responses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is @DataJpaTest in Spring Boot?

A

It is used for testing JPA repositories with an embedded database and limited Spring context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is @WebMvcTest used for in Spring Boot testing?

A

It is used for testing Spring MVC controllers by loading only the web layer of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does @TestConfiguration help in testing Spring applications?

A

It allows you to define additional beans or override existing ones specifically for test scenarios.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Spring TestContext Framework?

A

A testing framework in Spring that integrates with JUnit or TestNG to support Spring-based tests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is @Transactional used for in testing?

A

It rolls back transactions after each test method, ensuring a clean database state between tests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you test a Spring Boot REST API?

A

By using @RestClientTest or MockMvc to mock HTTP requests and validate responses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly