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

湖南公司注册网上核名seo优化关键词挖掘

湖南公司注册网上核名,seo优化关键词挖掘,高仿做的好点的网站,哪个企业做网站目录 1. 确保项目中包含相关依赖2. 配置JUnit 53. 编写测试类4、Junit5 新增特性4.1 注解4.2 断言4.3 嵌套测试4.4 总结 在Spring Boot 3中集成JUnit 5的步骤相对简单。以下是你可以按照的步骤#xff1a; 1. 确保项目中包含相关依赖 首先#xff0c;确保你的pom.xml文件中… 目录 1. 确保项目中包含相关依赖2. 配置JUnit 53. 编写测试类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支持 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!-- JUnit 5的依赖Spring Boot 3已经集成JUnit 5 dependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-api/artifactIdversion5.8.2/versionscopetest/scope/dependencydependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-engine/artifactIdversion5.8.2/versionscopetest/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);}TestDisabled(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 {StackObject stack;TestDisplayName(is instantiated with new Stack())void isInstantiatedWithNew() {new Stack();}NestedDisplayName(when new)class WhenNew {BeforeEachvoid createNewStack() {stack new Stack();}TestDisplayName(is empty)void isEmpty() {assertTrue(stack.isEmpty());}TestDisplayName(throws EmptyStackException when popped)void throwsExceptionWhenPopped() {assertThrows(EmptyStackException.class, stack::pop);}TestDisplayName(throws EmptyStackException when peeked)void throwsExceptionWhenPeeked() {assertThrows(EmptyStackException.class, stack::peek);}NestedDisplayName(after pushing an element)class AfterPushing {String anElement an element;BeforeEachvoid pushAnElement() {stack.push(anElement);}TestDisplayName(it is no longer empty)void isNotEmpty() {assertFalse(stack.isEmpty());}TestDisplayName(returns the element when popped and is empty)void returnElementWhenPopped() {assertEquals(anElement, stack.pop());assertTrue(stack.isEmpty());}TestDisplayName(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 StreamString method() {return Stream.of(apple, banana); }总结 Spring Boot 3已经内建了对JUnit 5的支持只要使用spring-boot-starter-test依赖即可。编写JUnit 5测试时使用SpringBootTest加载应用上下文。可以利用JUnit 5的生命周期方法、参数化测试等特性进行更精细的测试。
http://www.dnsts.com.cn/news/59225.html

相关文章:

  • 网站不备案做电影网站架设销售网站
  • 徐州网站制作公司哪家好上海网站建设的网站
  • 网站开发项目团队人员电商网站建设公司怎么样
  • 建立一个网站需要多少钱费用网站开发预算编制
  • 做网站的贴吧建设银行采购网站
  • 中国网站建设市场规模网站建设服务流程
  • 360doc 网站怎么做做软装的网站
  • 百度关键词查询网站手机网站html5
  • 机械产品做那几个网站好北京网站主题制作
  • 做网站谈单广州网站建设平台
  • 安阳做网站的公司有哪些域名后有个wordpress
  • 做这种灰色的网站犯法哪家外贸网站做的好
  • 门户网站是指提供什么的网站织梦网站上线
  • 网站后台管理功能网站建设 考题
  • 怎么做商品购买网站网站需要写哪些内容吗
  • 长安网站建设网络推广上海建筑设计研究院有限公司
  • 做销售在哪些网站发贴在线教育oem平台
  • 功能开发工程师建网站seo
  • 天津地产网站建设网站description
  • 宁夏电力建设工程公司门户网站找论文的免费网站
  • 网站建设后的优势与网站建设关系密切的知识点
  • 郑州网站建设知名公司排名惠阳有做公司网站的吗
  • 做网站卖别人的软件可以吗中国展陈公司前十名
  • 美丽乡村网站建设模板西安市建设工程交易信息网
  • phpstudy做网站运营的坏处如何看一个网站是否做推广
  • 租车网站系统规划51网站一起做网店广州
  • 如何做网站商城彩票网站开发 添加彩种教程
  • 销售型企业网站有哪些男的做直播哪个网站好
  • 网站建设全流程图wordpress 添加 联系我们
  • 昊源建设监理有限公司网站wordpress自然志