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

a站在线观看人数在哪企业网站代码html

a站在线观看人数在哪,企业网站代码html,外围网站开发,wordpress网关充值断言是测试用例的一部分#xff0c;也是测试工程师开发测试用例的核心。断言通常集成在单元测试和集成测试中#xff0c;断言分为硬断言和软断言。 硬断言是我们狭义上听到的普通断言:当用例运行后得到的[实际]结果与预期结果不匹配时#xff0c;测试框架将停止测试执行并抛…断言是测试用例的一部分也是测试工程师开发测试用例的核心。断言通常集成在单元测试和集成测试中断言分为硬断言和软断言。 硬断言是我们狭义上听到的普通断言:当用例运行后得到的[实际]结果与预期结果不匹配时测试框架将停止测试执行并抛出断言错误。如下面的案例测试执行在第一个失败时停止即使测试中有更多的断言也不会继续执行。 import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Test;class HardAssertionTest {Testvoid hardAssertion() {var person Person.builder().name(John).phoneNumber(null).age(16).build();assertThat(person.getName()).isNotBlank();assertThat(person.getPhoneNumber()).isNotNull();assertThat(person.getAge()).isGreaterThan(18);} } 第10行断言失败则第11行和第12行的断言将不会被执行。 java.lang.AssertionError: Expecting actual not to be null 通常来说硬断言在断言失败情况下终止测试执行是无可厚非的。但是在某些情况下我们想知道被断言的“对象”里哪些属性是不符合预期的这样使用软断言将解决这个问题。 什么是软断言? 软断言当一个测试用例中存在多个断言当有一个断言失败时会执行后续的断言。 支持软断言的工具通常使用下面的伪代码实现。 SoftAssertion softAssertion new SoftAssertion()softAssertion.assertSomething... softAssertion.assertAnotherThing... softAssertion.assertTheLastThing...softAssertion.assertThenAll(); 什么情况下使用软断言? 当测试用例有多个断言时候应该使用软断言。因为知道所有断言是否与预期结果一致可以减少多次运行测试以了解哪些不通过。 当测试用例有不止一条断言时软断言就要到位了。 支持软断言的工具 TestNG TestNG有一个SoftAssert类它的功能与前面介绍的伪代码相同:它对断言进行分组并在我们调用特定方法时立即进行验证。 来看一个软断言的案例 public class SoftAssertTestNGTest {Testpublic void testNGSoftAssertion() {var person Person.builder().name(John).phoneNumber(null).age(16).build();SoftAssert softAssert new SoftAssert();softAssert.assertEquals(person.getName(), John);softAssert.assertNotNull(person.getPhoneNumber(), Phone number cannot be null);softAssert.assertEquals(person.getAge(), 25, Age should be equal);softAssert.assertAll();} } 在例子中我们断言:phoneNumber不能为空年龄必须等于25。 第8到10行使用softAssertion在断言方法之前告诉代码它属于SoftAssertion类。可以使用TestNG支持的任何断言方法实现。第12行调用assertAll ()方法该方法将运行与softAssertion引用关联的所有断言 我们可以看到显示一个断言失败而TestNG没有停止测试执行而是运行所有的断言显示所有的失败。 java.lang.AssertionError: The following asserts failed:Phone number cannot be null Expected :25 Actual :16 Click to see difference JUnit 5 JUnit 5使用assertAll()方法作为软断言方法。它不需要使用外部特定类它已经是断言类的一部分。我们需要做的就是静态方式导入它。 例子: import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;class SoftAssertionJunit5Test {Testvoid softAssertionUsingJUnit5() {var person Person.builder().name(John).phoneNumber(null).age(16).build();assertAll(person,() - assertNotNull(person.getName(), Name must not be null),() - assertNotNull(person.getPhoneNumber(), Phone number should not be null),() - assertEquals(18., person.getAge(), Age must be 18));} } 第12行显示了使用两个参数的assertAll()方法 一个标题一个流式的可执行的命令即断言方法 第13到15行显示了stream的用法每个stream用于我们必须应用的任何断言 执行结果如下: org.opentest4j.AssertionFailedError: Phone number should not be null expected: not nullat org.example.SoftAssertionJunit5Test.lambda$softAssertionUsingJUnit5$1(SoftAssertionJunit5Test.java:17)org.opentest4j.AssertionFailedError: Age must be 18 Expected :18.0 Actual :16.0at org.example.SoftAssertionJunit5Test.lambda$softAssertionUsingJUnit5$2(SoftAssertionJunit5Test.java:18)org.opentest4j.MultipleFailuresError: person (2 failures)org.opentest4j.AssertionFailedError: Phone number should not be null expected: not nullorg.opentest4j.AssertionFailedError: Age must be 18 expected: 18.0 but was: 16.0 AssertJ AssertJ断言库提供了软断言的不同方法并可以创建自己的断言: 调用assertAll ()使用autocloseableoftassertion使用静态方法assertsoft 我们可以使用所有这些不同的方法来应用它并在AssertJ页面上查看所有示例。这里可以看到assertsoft静态方法的使用案例。 import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Test;class SoftAssertionTest {Testvoid softAssertionUsingAssertJ() {var person Person.builder().name(John).phoneNumber(null).age(16).build();SoftAssertions.assertSoftly(softly - {softly.assertThat(person.getName()).isNotBlank();softly.assertThat(person.getPhoneNumber()).isNotNull();softly.assertThat(person.getAge()).isGreaterThan(18);});} } 异常输出如下: java.lang.AssertionError: Expecting actual not to be null at SoftAssertionTest.lambda$assertJSoftAssertion$0(SoftAssertionTest.java:16)java.lang.AssertionError: Expecting actual:16 to be greater than:18 at SoftAssertionTest.lambda$assertJSoftAssertion$0(SoftAssertionTest.java:17)org.assertj.core.error.AssertJMultipleFailuresError: Multiple Failures (2 failures) -- failure 1 -- Expecting actual not to be null at SoftAssertionTest.lambda$assertJSoftAssertion$0(SoftAssertionTest.java:16) -- failure 2 -- Expecting actual:16 to be greater than:18 at SoftAssertionTest.lambda$assertJSoftAssertion$0(SoftAssertionTest.java:17) AssertionErrors列表及其完整的堆栈信息带有断言失败的摘要信息
http://www.dnsts.com.cn/news/71080.html

相关文章:

  • 龙口网站建设公司报价计算机专业的会学怎么做网站吗
  • 网站建设前 需要准备的网站注册查询官网
  • 电子商务网站建设大二实训wordpress整站导出
  • 深圳最专业的高端网站建设产品创意设计作品
  • 中国交通建设集团网站管理系统界面设计
  • 网站建设hyioi能浏览外国网页的浏览器
  • 西安地产网站制作公司wordpress默认主题
  • 在南海建设工程交易中心网站电子科技网站建设
  • 万能网站浏览器深圳信用网官网
  • 装饰网站建设网站建设公司起名
  • 建设企业网站制作公司东莞网站制作与网站建设
  • 免费网站建设 百度一下硬件开发管理流程
  • 昌邑市住房和建设局网站seo关键词是什么意思
  • 企业门户网站建设专业品牌跨境电商多平台运营
  • 互联网站备案登记表网站提升权重
  • 1000元能否做网站织梦整合wordpress
  • 沧州seo推广优化网站排名费用
  • 自己在网上怎么做网站网络推广培训学费几万
  • 厦门软件园网站开发seo推广网站有哪
  • 网站建设基本概述宁波网络推广加盟
  • 平湖市住房和城乡规划建设局网站营销型网站有哪些功能
  • 暗色系网站代理公司注册登记
  • 免费做网站哪里有创新的做网站
  • 住房建设厅官方网站wordpress跳转代码
  • 网站地图怎么设置北京英文网站建设的原则
  • 资阳地网站建设手机移动开发网站建设
  • 网站开发需求报告模板下载html5网站建设公司
  • 做房地产策划需要关注的网站微信小程序怎么做问卷调查
  • 网站做电商销售需要注册吗官网seo是什么意思
  • 网站短链接生成器网站 所有权