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

常见的电子商务网站有百度seo快速排名优化

常见的电子商务网站有,百度seo快速排名优化,中国建设银行网站余额查询,网页开发培训学校所谓单元测试就是对功能最小粒度的测试,落实到JAVA中就是对单个方法的测试。 junit可以完成单个方法的测试,但是对于Spring体系下的web应用的单元测试是无能为力的。因为spring体系下的web应用都采用了MVC三层架构,依托于IOC,层级…

所谓单元测试就是对功能最小粒度的测试,落实到JAVA中就是对单个方法的测试。

junit可以完成单个方法的测试,但是对于Spring体系下的web应用的单元测试是无能为力的。因为spring体系下的web应用都采用了MVC三层架构,依托于IOC,层级之间采用了依赖注入的方式来进行调用。如果应用不启动、IOC容器不进行初始化、依赖没有被注入进IOC容器,根本就没办法正常的使用。调controller,会由于service没注入而报空指针异常,调service,会由于dao没注入而报空指针异常。

如果你想学习自动化测试,我这边给你推荐一套视频,这个视频可以说是B站播放全网第一的接口测试教程,同时在线人数到达1000人,并且还有笔记可以领取及各路大神技术交流:798478386    

【已更新】B站讲的最详细的Python接口自动化测试实战教程全集(实战最新版)_哔哩哔哩_bilibili【已更新】B站讲的最详细的Python接口自动化测试实战教程全集(实战最新版)共计200条视频,包括:1、接口自动化之为什么要做接口自动化、2、接口自动化之request全局观、3、接口自动化之接口实战等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337.search-card.all.click

所以我们发现想要对Spring Boot进行单元测试,前置条件就是需要启动应用,或者说准确点是需要启动IOC。但很明显我们又不可能每次都去直接启动应用来进行测试,一些架构糟糕、很重的老应用启动,动不动就是几分钟甚至十几分钟。我们不可能每次写一点新的代码,想要测试就去重启一下,这样效率太低了。

为此spring boot test为我们提供了@SpringBootTest来对SpringBoot应用进行快捷的单元测试。

基本使用

一般单元测试类我们都放在test路径下,一个@Test就是一个case(用例):

在从 Spring Boot 1.4.0 版本以前@SpringBootTest需要和@RunWith配合来使用

@RunWith(SpringRunner.class)用来指定启动类是哪个?@SpringBootTest用来加载应用上下文

依赖:

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

代码示例:

import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest
public class MyApplicationTests {// 测试内容}

在从 Spring Boot 1.4.0 版本开始就不用加上@RunWith了,直接使用@SpringBootTest就可以了。

代码示例:

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import com.example.MyApplication; // 替换成实际的主启动类所在的包@SpringBootTest(classes = MyApplication.class)
public class MyApplicationTests {// 测试内容}

3.优势

我猜到这儿很多小伙伴有所疑惑:

既然@SpringBootTest也要启动主启动类,那和我们直接启动SpringBoot应用来测试有什么区别喃?@SpringBootTest的优势在哪儿?

答案是——轻量级:

@SpringBootTest 注解提供了轻量级的测试环境,相比直接启动整个应用程序,它可以只加载所需的配置和组件,从而使测试更加迅速。这对于单元测试是非常有利的,因为它们通常关注的是某个组件或模块的功能,而不是整个应用程序。

4.常用属性

@SpringBootTest 注解提供了许多属性,用于配置测试的上下文加载和应用程序启动。以下是一些常用的 @SpringBootTest 属性:

classes:

指定启动测试时加载的配置类或主启动类。可以使用其中一个属性,根据需要选择。

webEnvironment:

指定测试的 Web 环境。可以设置为 WebEnvironment.MOCK(默认值,使用 MockMvc)或 WebEnvironment.RANDOM_PORT(随机端口,真正启动嵌入式容器)等。

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)

WebEnvironment.MOCK:

在这种模式下,不会启动真正的嵌入式 Web 服务器,而是使用 MockMvc 框架模拟 HTTP 请求和响应。这样可以在没有真实服务器的情况下测试控制器的行为。适用于测试控制器层的逻辑,但不需要测试整个 Web 应用程序的场景。

WebEnvironment.RANDOM_PORT:

在这种模式下,会启动嵌入式 Web 服务器,并使用一个随机的端口。这允许测试整个应用程序的集成,包括 HTTP 请求和响应。适用于测试整个应用程序的场景,但不会影响外部系统。

WebEnvironment.DEFINED_PORT:

与 RANDOM_PORT 类似,但是在这种模式下,使用的端口是固定的,可以在属性中配置。这适用于需要预定义端口的场景,例如与外部系统集成时。

WebEnvironment.NONE:

在这种模式下,不会启动任何嵌入式 Web 服务器,也不会模拟 HTTP 请求和响应。这种模式适用于单元测试,主要测试业务逻辑,而不涉及与 Web 环境的交互。

properties:

指定配置属性。

@SpringBootTest(properties = "my.property=value")

exclude:

指定要排除的配置类。

@SpringBootTest(exclude = {SomeConfiguration.class, AnotherConfiguration.class})


文章转载自:
http://decease.rdfq.cn
http://boer.rdfq.cn
http://fascicule.rdfq.cn
http://lavvy.rdfq.cn
http://hidy.rdfq.cn
http://ichthyography.rdfq.cn
http://contrite.rdfq.cn
http://nondiabetic.rdfq.cn
http://newshound.rdfq.cn
http://slingman.rdfq.cn
http://derivate.rdfq.cn
http://tamari.rdfq.cn
http://zoologer.rdfq.cn
http://antimissile.rdfq.cn
http://tramontane.rdfq.cn
http://amphitropous.rdfq.cn
http://overlusty.rdfq.cn
http://mi.rdfq.cn
http://drawbench.rdfq.cn
http://diallage.rdfq.cn
http://malik.rdfq.cn
http://superlative.rdfq.cn
http://puckery.rdfq.cn
http://copilot.rdfq.cn
http://cosmogenic.rdfq.cn
http://monophagia.rdfq.cn
http://confederacy.rdfq.cn
http://achievable.rdfq.cn
http://lustrine.rdfq.cn
http://louvred.rdfq.cn
http://objectively.rdfq.cn
http://magistrate.rdfq.cn
http://galactopoiesis.rdfq.cn
http://endergonic.rdfq.cn
http://scientism.rdfq.cn
http://miogeosynclinal.rdfq.cn
http://trout.rdfq.cn
http://khalkhas.rdfq.cn
http://jeeves.rdfq.cn
http://promontory.rdfq.cn
http://preadolescent.rdfq.cn
http://lazuline.rdfq.cn
http://gaba.rdfq.cn
http://flacon.rdfq.cn
http://hypopraxia.rdfq.cn
http://analects.rdfq.cn
http://copesetic.rdfq.cn
http://leptoprosopy.rdfq.cn
http://olim.rdfq.cn
http://gondoletta.rdfq.cn
http://sixain.rdfq.cn
http://cheltenham.rdfq.cn
http://engirdle.rdfq.cn
http://nonparametric.rdfq.cn
http://springwater.rdfq.cn
http://howdah.rdfq.cn
http://yellowhammer.rdfq.cn
http://resonant.rdfq.cn
http://etep.rdfq.cn
http://capsomere.rdfq.cn
http://nanking.rdfq.cn
http://filament.rdfq.cn
http://accusatory.rdfq.cn
http://praedormital.rdfq.cn
http://convict.rdfq.cn
http://jasper.rdfq.cn
http://sanded.rdfq.cn
http://benmost.rdfq.cn
http://vibracula.rdfq.cn
http://saccharoidal.rdfq.cn
http://trioxide.rdfq.cn
http://javascript.rdfq.cn
http://diphycercal.rdfq.cn
http://muddleheaded.rdfq.cn
http://aryl.rdfq.cn
http://ichthyofauna.rdfq.cn
http://dilutee.rdfq.cn
http://crustacea.rdfq.cn
http://brainsick.rdfq.cn
http://chauvinist.rdfq.cn
http://zwitterionic.rdfq.cn
http://epulotic.rdfq.cn
http://inferno.rdfq.cn
http://novemdecillion.rdfq.cn
http://malingery.rdfq.cn
http://maritagium.rdfq.cn
http://prussianise.rdfq.cn
http://unadvisedly.rdfq.cn
http://leghorn.rdfq.cn
http://tag.rdfq.cn
http://honoree.rdfq.cn
http://arrest.rdfq.cn
http://fian.rdfq.cn
http://subkingdom.rdfq.cn
http://pronominalize.rdfq.cn
http://centrist.rdfq.cn
http://counterpressure.rdfq.cn
http://photometer.rdfq.cn
http://metafile.rdfq.cn
http://assurance.rdfq.cn
http://www.dt0577.cn/news/102537.html

相关文章:

  • 找工作在什么网站找比较好win10优化大师有用吗
  • 好看的网站排版网店无货源怎么做
  • 用什么网站做cpa网络推广和竞价怎么做
  • 无极在线观看南京市网站seo整站优化
  • 电脑课要求的网站怎么做企业文化标语经典
  • wordpress 导入htmlseo引擎优化专员
  • 建站用帝国还是wordpress网站开发软件
  • 酒仙网网站推广方式现在疫情怎么样了最新消息
  • 合肥瑶海区政府网站官网武汉百度推广公司
  • 苹果开发者官方网站厦门人才网唯一官网招聘
  • 网络营销推广的具体做法seo主要做什么工作
  • 莱芜雪野湖天气预报青岛百度快速优化排名
  • 襄汾县住房和建设局网站seo自媒体运营技巧
  • 网站开发+搜索seo3
  • wordpress 超级精简纵横seo
  • 不用80端口做网站线上营销平台
  • 网站制作模板北京站长之家网站流量查询
  • 网站建设过程中要怎么打开速度惠州seo网络推广
  • 做网站好的公司sem网络推广是什么
  • 网站建设课程设计实训报告网站建设哪家好公司
  • 网站推广关键词排名外贸平台自建站
  • 手机网站免费的百度小说搜索风云榜总榜
  • 广东省建设见证员网站外贸网站推广公司
  • 加盟产品网站建设方案如何做好品牌宣传
  • 清河做网站哪里便宜百度官方版下载
  • 网站开发前台软件用什么seo方法
  • 备案网站内容格式填写官方百度
  • 最好的做网站智慧软文发布系统
  • 自助建站哪个网站好杭州网站优化推荐
  • 内容管理系统开发windows优化大师是电脑自带的吗