A simple understanding of Spring Boot 1.4 testing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.