Spring boot - Testing Flashcards

(8 cards)

1
Q

@SpringBootTest

A

-Starts the full application context. It injects all beans (repositories, services, controllers etc)
- Sets up a transactional rollback, Auto configures a H2 test database
- Provides utilities like:
- @MockitoBean - for replacing real beans
- @DataJpaTest - for fast JPA-only integration tests
- @WebMvcTest - for controller-level tests

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

@Test

A

Marks a method as a test case, the JUnit runtime will scan the classes, find methods with the @Test annotation and execute them as part of the test suite

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

@DisplayName

A

Provides a readable name for the test

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

@DataJpaTest

A

Only loads the Jpa related parts of the spring context, by default it uses H2, in memory database

@DataJpaTest
class RepoTest{}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of @WebMvcTest?

A

It tests only the web layer (controllers and MVC components) without loading the full context, typically using MockMvc to simulate HTTP requests

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

@Mock

A

used to create a mock instance of a class or
interface

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

@InjectMocks

A

annotation is used to create an instance of
the class you want to test and automatically inject the
fields marked with @Mock

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

@ExtendWith(MockitoExtension.class)

A

Mockito annotations need to be enabled in Junit 5 using
this class annotation

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