美文网首页
spring单元测试

spring单元测试

作者: 水煮鱼又失败了 | 来源:发表于2020-06-29 10:13 被阅读0次

1 spring单元测试

1.1 引入maven依赖

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>5.2.2.RELEASE</version>
</dependency>
<dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.13</version>
     <scope>test</scope>
</dependency>

1.2 执行代码

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml"})
public class TmpSpringTest {
    @Test
    public void myTest(){
        System.out.println("My junit test method...");
    }
}

2 springBoot单元测试

2.1 引入maven依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>2.3.1.RELEASE</version>
    <scope>test</scope>
</dependency>

2.2 执行代码

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class DemoApplicationTests {
    @Test
    void contextLoads() {
        System.out.println("My junit test method...");
    }
}

相关文章

网友评论

      本文标题:spring单元测试

      本文链接:https://www.haomeiwen.com/subject/hlxofktx.html