lundi 11 juillet 2016

Is there a way to AutoWire WebApplicationContext in a test run by Mockito

I have a very simple unit test:

@RunWith(MockitoJUnitRunner.class)
public class RestControllerTest {

    protected MockMvc mockMvc;

    @Autowired
    WebApplicationContext wac;

    @InjectMocks
    protected RestController restController;

    @Mock
    protected UserService mockUserService;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);


        }
    }

I am stuck at figuring out how to Autowire WebApplicationContext in the above test. Please can somebody guide me how to do this.

P.S. I am using MockitoJUnitRunner I am not sure if this makes a difference or no. But I am new to Spring and Mockito so dont know much about either technologies.

Aucun commentaire:

Enregistrer un commentaire