zoukankan      html  css  js  c++  java
  • SpringBoot 单元测试junit test

    pom引用

    <?xml version="1.0" encoding="UTF-8"?>
    
    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.yyit</groupId>
        <artifactId>demo</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    
        <name>demo</name>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.9.RELEASE</version>
            <relativePath/>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <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>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.6</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.30</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>

    Application.java

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }

    测试代码

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = Application.class)
    public class AppTest {
    
        @Autowired
        private BookRepository bookRepository;
    
        @Test
        public void testgetPidList4MdmCrop() {
    
            Book book = bookRepository.findByName("abc");
    
            System.out.println(book.toString());
    
        }
    
    }
  • 相关阅读:
    开启power management功能有坑,ESP32串口频繁出现UART_BREAK中断
    ESP32音频开发板ESP32-Korvo V1.1踩坑
    驱动开发常用位运算
    ESP8266 RTOS 开发笔记(4)串口透传
    mosquitto服务状态监控(转载)
    ESP8266 RTOS 开发笔记(3)用户参数
    ESP8266 RTOS 开发笔记(2)TCP Client+Server
    ESP8266 RTOS 开发笔记(1)STA+AP模式(共存)
    C uint32 转 uint8
    python 简易计算器(只能计算加减乘除和括号)
  • 原文地址:https://www.cnblogs.com/liuxm2017/p/9915603.html
Copyright © 2011-2022 走看看