Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cant i import @WithMockUser to my test

Tags:

spring-boot

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

like image 791
valik Avatar asked Oct 14 '17 15:10

valik


2 Answers

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>
like image 87
Anton Nakonechnyi Avatar answered Sep 19 '22 15:09

Anton Nakonechnyi


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>
like image 37
Boston Hack Avatar answered Sep 17 '22 15:09

Boston Hack