当前位置: 首页 > news >正文

wordpress showcase百度seo营销推广多少钱

wordpress showcase,百度seo营销推广多少钱,网页美工实训总结,上海网站建设系目录 1. 确保项目中包含相关依赖2. 配置JUnit 53. 编写测试类4、Junit5 新增特性4.1 注解4.2 断言4.3 嵌套测试4.4 总结 在Spring Boot 3中集成JUnit 5的步骤相对简单。以下是你可以按照的步骤: 1. 确保项目中包含相关依赖 首先,确保你的pom.xml文件中…

目录

      • 1. 确保项目中包含相关依赖
      • 2. 配置JUnit 5
      • 3. 编写测试类
      • 4、Junit5 新增特性
        • 4.1 注解
        • 4.2 断言
        • 4.3 嵌套测试
        • 4.4
      • 总结

在Spring Boot 3中集成JUnit 5的步骤相对简单。以下是你可以按照的步骤:

1. 确保项目中包含相关依赖

首先,确保你的pom.xml文件中包含了Spring Boot 3和JUnit 5相关的依赖。下面是需要的基本依赖:

<dependencies><!-- Spring Boot Starter Test(包含JUnit 5支持) --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- JUnit 5的依赖(Spring Boot 3已经集成JUnit 5) <dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.8.2</version><scope>test</scope></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-engine</artifactId><version>5.8.2</version><scope>test</scope></dependency> -->
</dependencies>

注意spring-boot-starter-test 默认包含JUnit 5支持,所以你不需要显式地引入JUnit 5的依赖,除非你有特定版本的需求。

2. 配置JUnit 5

Spring Boot 3默认启用了JUnit 5,你只需要按照JUnit 5的方式编写测试代码即可。Spring Boot的@SpringBootTest注解会与JUnit 5兼容。

3. 编写测试类

创建一个简单的JUnit 5测试类,使用@SpringBootTest来加载Spring Boot应用程序上下文。

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
class MyApplicationTests {@Testvoid test() {// 这里写测试方法}
}

4、Junit5 新增特性

4.1 注解

JUnit5的注解与JUnit4的注解有所变化
https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations
● @Test :表示方法是测试方法。但是与JUnit4的@Test不同,他的职责非常单一不能声明任何属性,拓展的测试将会由Jupiter提供额外测试
● @ParameterizedTest :表示方法是参数化测试,下方会有详细介绍
● @RepeatedTest :表示方法可重复执行,下方会有详细介绍
● @DisplayName :为测试类或者测试方法设置展示名称
● @BeforeEach :表示在每个单元测试之前执行
● @AfterEach :表示在每个单元测试之后执行
● @BeforeAll :表示在所有单元测试之前执行
● @AfterAll :表示在所有单元测试之后执行
● @Tag :表示单元测试类别,类似于JUnit4中的@Categories
● @Disabled :表示测试类或测试方法不执行,类似于JUnit4中的@Ignore
● @Timeout :表示测试方法运行如果超过了指定时间将会返回错误
● @ExtendWith :为测试类或测试方法提供扩展类引用

import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;class StandardTests {@BeforeAllstatic void initAll() {}@BeforeEachvoid init() {}@DisplayName("😱")@Testvoid succeedingTest() {}@Testvoid failingTest() {fail("a failing test");}@Test@Disabled("for demonstration purposes")void skippedTest() {// not executed}@Testvoid abortedTest() {assumeTrue("abc".contains("Z"));fail("test should have been aborted");}@AfterEachvoid tearDown() {}@AfterAllstatic void tearDownAll() {}}
4.2 断言

在这里插入图片描述

4.3 嵌套测试

JUnit 5 可以通过 Java 中的内部类和@Nested 注解实现嵌套测试,从而可以更好的把相关的测试方法组织在一起。在内部类中可以使用@BeforeEach 和@AfterEach 注解,而且嵌套的层次没有限制。

@DisplayName("A stack")
class TestingAStackDemo {Stack<Object> stack;@Test@DisplayName("is instantiated with new Stack()")void isInstantiatedWithNew() {new Stack<>();}@Nested@DisplayName("when new")class WhenNew {@BeforeEachvoid createNewStack() {stack = new Stack<>();}@Test@DisplayName("is empty")void isEmpty() {assertTrue(stack.isEmpty());}@Test@DisplayName("throws EmptyStackException when popped")void throwsExceptionWhenPopped() {assertThrows(EmptyStackException.class, stack::pop);}@Test@DisplayName("throws EmptyStackException when peeked")void throwsExceptionWhenPeeked() {assertThrows(EmptyStackException.class, stack::peek);}@Nested@DisplayName("after pushing an element")class AfterPushing {String anElement = "an element";@BeforeEachvoid pushAnElement() {stack.push(anElement);}@Test@DisplayName("it is no longer empty")void isNotEmpty() {assertFalse(stack.isEmpty());}@Test@DisplayName("returns the element when popped and is empty")void returnElementWhenPopped() {assertEquals(anElement, stack.pop());assertTrue(stack.isEmpty());}@Test@DisplayName("returns the element when peeked but remains not empty")void returnElementWhenPeeked() {assertEquals(anElement, stack.peek());assertFalse(stack.isEmpty());}}}
}
4.4

参数化测试是JUnit5很重要的一个新特性,它使得用不同的参数多次运行测试成为了可能,也为我们的单元测试带来许多便利。

利用@ValueSource等注解,指定入参,我们将可以使用不同的参数进行多次单元测试,而不需要每新增一个参数就新增一个单元测试,省去了很多冗余代码。

@ValueSource: 为参数化测试指定入参来源,支持八大基础类以及String类型,Class类型
@NullSource: 表示为参数化测试提供一个null的入参
@EnumSource: 表示为参数化测试提供一个枚举入参
@CsvFileSource:表示读取指定CSV文件内容作为参数化测试入参
@MethodSource:表示读取指定方法的返回值作为参数化测试入参(注意方法返回需要是一个流)

@ParameterizedTest
@ValueSource(strings = {"one", "two", "three"})
@DisplayName("参数化测试1")
public void parameterizedTest1(String string) {System.out.println(string);Assertions.assertTrue(StringUtils.isNotBlank(string));
}@ParameterizedTest
@MethodSource("method")    //指定方法名
@DisplayName("方法来源参数")
public void testWithExplicitLocalMethodSource(String name) {System.out.println(name);Assertions.assertNotNull(name);
}static Stream<String> method() {return Stream.of("apple", "banana");
}

总结

  • Spring Boot 3已经内建了对JUnit 5的支持,只要使用spring-boot-starter-test依赖即可。
  • 编写JUnit 5测试时,使用@SpringBootTest加载应用上下文。
  • 可以利用JUnit 5的生命周期方法、参数化测试等特性进行更精细的测试。
http://www.hrbkazy.com/news/16791.html

相关文章:

  • 做印刷哪个网站好百度站长快速收录
  • 做网站网页尺寸是多少魔方优化大师官网
  • 长沙网站制作案例怎么让百度收录网站
  • python 网站开发 案例泰州网站建设优化
  • 做java面试题的网站网站关键词优化推广
  • 网站建设合同的注意点关键词是怎么排名的
  • 自己做的网站怎么设置关键词营销推广的工具有哪些
  • go做后端的网站保健品的营销及推广方案
  • 建设银行洛阳市分行网站seo应该如何做
  • 网站 开发百度识图搜索引擎
  • 娄底市住房和城乡建设局网站网上怎么注册公司免费的
  • 网站建设招标无代码网站开发平台
  • 密云做网站的yoast seo教程
  • seo竞价排名安徽seo人员
  • 网站开发流程三部分互联网营销推广公司
  • 每日财经新闻东莞整站优化
  • 深圳市营销策划有限公司成都网站优化排名
  • 网站建设 上海珍岛产品营销推广方案
  • 狮山做网站推广优化seo
  • 网站必须做电子认证吗优化工具箱
  • 南昌市做网站公司杭州专业seo公司
  • 重庆市工程造价信息网查询长春最专业的seo公司
  • 怎样建设一个网站赚钱上海百度seo点击软件
  • 潍坊建立企业网站公司网站策划方案案例
  • 用jsp做网站的难点什么是搜索引擎营销
  • 高端手机网站建设网站域名查询ip
  • 和外国人做古玩生意的网站武汉大学人民医院
  • oss做下载网站百度客户端在哪里打开
  • 网站建设服务 杭州千牛怎么做免费推广引流
  • 淘客做网站太原seo排名收费