I am trying to do an authentication test with @With Mock User but it is refusing to import to my test class in spring boot . This is the class configuration
@WebAppConfiguration
@AutoConfigureMockMvc
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = AdminPortalApplication.class)
public class BookControllerTest {
@WithMockUser not able to import ,its red in color showing that spring boot does not recognize it, I used this dependency and property
<spring-security.version>4.0.2.RELEASE</spring-security.version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Keeps saying cannot resolve symbol @WithMockUser
Try fresh dependency. I just solved such issue with this one:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
Add an import statement for the library:
import org.springframework.security.test.context.support.WithMockUser;
And declare a dependency in your pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With