Spring Security Mock MVC Test

Hi I am trying to use Spring to test my controller but here is the definition of my test class:
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.MOCK,
classes = [ProfileController::class]
)
@AutoConfigureMockMvc(addFilters = false)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
@ActiveProfiles("test", REST_API_PROFILE_NAME)
@DisplayName("Profile Controller Test")
class ProfileControllerTest
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.MOCK,
classes = [ProfileController::class]
)
@AutoConfigureMockMvc(addFilters = false)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
@ActiveProfiles("test", REST_API_PROFILE_NAME)
@DisplayName("Profile Controller Test")
class ProfileControllerTest
In the SpringBootTest#classes method I specified my controller but when I run it, Spring doesn't automatically create all needed beans for example ProfileService or ProfileDao
2 Replies
JavaBot
JavaBot15mo ago
This post has been reserved for your question.
Hey @Pseudow! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot15mo ago
Post Closed
This post has been closed by <@1123703840739442698>.

Did you find this page helpful?