August 2018
Intermediate to advanced
372 pages
9h 29m
English
Testing is crucial to our applications. When we use Spring MVC, we can count on the spring-test module to add support for unit and integration tests that are context-aware, which means that we can rely on annotations to wire dependencies. We can also use the @Autowired annotation to test a specific component.
The following is an example of how simple it is to write a test that is context-aware:
@RunWith(SpringRunner.class)@SpringBootTestpublic class ContextAwareTest { @Autowired ClassUnderTest classUnderTest; @Test public void validateAutowireWorks() throws Exception { Assert.assertNotNull(classUnderTest); }}
Let's review the code in bold, in order to understand how it works:
Read now
Unlock full access