• springboot--单元测试


    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.example</groupId>
      <artifactId>test-springboot</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      
      
      <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.9.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
      
    <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>
            
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.7.0</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.7.0</version>
            </dependency>
            
            
            <!-- <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.2</version>
            </dependency>
     
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency> -->
            
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.10</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>
    import java.net.URL;
    import java.util.List;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.boot.test.web.client.TestRestTemplate;
    import org.springframework.boot.web.server.LocalServerPort;
    import org.springframework.http.ResponseEntity;
    import org.springframework.test.context.junit4.SpringRunner;
    
    import com.example.App;
    import com.example.source.AppProperties;
    import com.example.source.OwnerProperties;
     
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    public class UserTest {
        
        
        @LocalServerPort
        private int port;
     
        private URL base;
        
        @Value("${maxupload}")
        private Long maxupload;
     
        @Autowired
        private TestRestTemplate restTemplate;
        
        
        @Autowired
        private AppProperties appProperties;
        
        @Autowired
        private OwnerProperties ownerProperties;
        
     
        @Before
        public void setUp() throws Exception {
            String url = String.format("http://localhost:%d/", port);
            System.out.println(String.format("port is : [%d]", port));
            this.base = new URL(url);
        }
     
        @Test
        public void test1() throws Exception {
    //        System.out.println(appProperties.getName());
    //        System.out.println(ownerProperties.getName());
            
            System.out.println(maxupload);
        }
        
        //@Test
        public void getAllTest() throws Exception {
            ResponseEntity<List> response = this.restTemplate.getForEntity(
                    this.base.toString() + "/getAll", List.class, "");
            System.out.println(String.format("测试结果为:%s", response.getBody()));
        }
        
        
     
    }
  • 相关阅读:
    iOSS--生成有logo的二维码
    inux网卡与MAC地址绑定方法总结
    Linux--多网卡的7种Bond模式
    Arp攻击实战
    5款免费Windows远程连接Linux桌面软件(VNC客户端)
    DenyHosts安装及配置
    Cacti完全使用手册 ( 让你快速个性化使用Cacti )
    解除被DenyHosts锁定的IP地址
    linux防止sshd被爆破(安装denyhosts)
    实现水电气一卡通 IC卡扇区分配
  • 原文地址:https://www.cnblogs.com/jentary/p/13602722.html
Copyright © 2020-2023  润新知