My question has to do with the application set-up, not mocking or using autowiring. See the answer for more details.
I\'m trying to set up a Spring Boot application
standaloneSetup
is used for unit tests. But it seems like you are doing integrations tests, so the below code should work - I have not tested it.
Replace
@Before
public void setup() throws Exception {
mockMvc = standaloneSetup(new MetricAPI()).build();
}
with
@Autowired
private WebApplicationContext wac;
@Before
public void setup() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
and add this to your test class:
@WebAppConfiguration
Bonus
@RunWith(SpringRunner.class) tells JUnit to run using Spring’s testing support. SpringRunner is the new name for SpringJUnit4ClassRunner, it’s just a bit easier on the eye.