First Maven wants to introduce spring-boot-starter-test
this package.
Look at a piece of code first
@RunWith (Springrunner. Class ) @SpringBootTest (webenvironment = Webenvironment.random_port) public class MyTest { @Autowired private testresttemplate resttemplate; @Test public void Test () { this .resttemplate.getforentity" ( "/{username}/vehicle", String. class , "Phil" ); }}
1. @RunWith (Springrunner.class) tells JUnit to run test support using spring. Springrunner is Springjunit4classrunner's new name, which simply makes the name look simple.
2. @SpringBootTest means "boot program with spring boot support" (for example, loading applications, attributes, giving us all the essentials of Spring boot).
3. The Webenvironment property allows a specific "network environment" to be configured for testing. You can start your test with a mock applet environment, or use a real HTTP server running on Random_port or Defined_port.
4. If we want to load a specific configuration, we can use the @springboottest class attribute. In this example, omitting classes means testing the first attempt to load the @ configuration from any inner-classes, if the attempt fails, it will be searched in your main @springbootapplicationclass.
A simple understanding of Spring Boot 1.4 testing