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

怎样做网站排名怎么删除WordPress外链

怎样做网站排名,怎么删除WordPress外链,网站开发公司的销售方式,网站建设和商城有什么好处assertj编写好的单元测试的规则之一是#xff0c;它应该由于一种原因而失败#xff0c;因此#xff0c;单元测试应该测试一种逻辑概念。 有时很难在每个测试中拥有一个断言。 为了遵循规则#xff0c;我们可能在单个测试中每个对象具有多个断言。 但是#xff0c;在一个测… assertj 编写好的单元测试的规则之一是它应该由于一种原因而失败因此单元测试应该测试一种逻辑概念。 有时很难在每个测试中拥有一个断言。 为了遵循规则我们可能在单个测试中每个对象具有多个断言。 但是在一个测试中存在多个断言的问题在于如果第一个断言由于任何原因而失败我们实际上将不知道其他断言因为它们将不会被执行。 并且您知道了演练您检查断言失败原因进行修复然后重新运行测试。 也许您很幸运测试会通过。 但是也许它将因另一个断言而失败。 对于真正快速的单元测试这不是什么大问题但是例如在进行Selenium测试时分析和故障检测可能会变得很麻烦并且肯定会很费时。 幸运的是借助AssertJ的SoftAssertions 我们可以重新考虑在测试中创建断言的SoftAssertions 。 一个宣称可以统治所有人的主张 在假设的Dice游戏中有一个Score对象其中保存得分值骰子组合和提醒。 在单元测试中我们可能想验证不同骰子组合的分数是如何计算的。 在下面的示例中验证了一个概念分数对象 Test public void verifiesScore() {Score score Score.scoreBuilder().withValue(11).withCombination(dice(1, 1, 3, 4)).withReminder(dice(6)).build();assertThat(score.getValue()).as(Has score).isEqualTo(8);assertThat(score.getCombination()).as(Has combination).isEqualTo(dice(1, 1, 3, 3));assertThat(score.getReminder()).as(Has reminder).isEqualTo(dice(5)); } 如您所见所有三个断言都失败了但是由于第一个失败后测试的执行停止因此我们只会看到第一个失败的结果 org.junit.ComparisonFailure: [Has score] Expected :8 Actual :11引入 为了解决这个问题我们可以使用SoftAssertions 它将在调用assertAll()方法时立即收集所有断言的结果 Test public void verifiesScoreSoftly() {Score score Score.scoreBuilder().withValue(11).withCombination(dice(1, 1, 3, 4)).withReminder(dice(6)).build();SoftAssertions softAssertions new SoftAssertions();softAssertions.assertThat(score.getValue()).as(Has score).isEqualTo(8);softAssertions.assertThat(score.getCombination()).as(Has combination).isEqualTo(dice(1, 1, 3, 3));softAssertions.assertThat(score.getReminder()).as(Has reminder).isEqualTo(dice(5));softAssertions.assertAll(); } 现在我们可以验证测试中的所有断言失败 org.assertj.core.api.SoftAssertionError: The following 3 assertions failed: 1) [Has score] expected:[8] but was:[11] 2) [Has combination] expected:...alue3}, Dice{value[3]}] but was:...alue3}, Dice{value[4]}] 3) [Has reminder] expected:[Dice{value[5]}] but was:[Dice{value[6]}]JUnitSoftAssertions 代替手动创建SoftAssertions并调用其assertAll()我们可以使用JUnit Rule Rule public JUnitSoftAssertions softAssertions new JUnitSoftAssertions();Test public void verifiesScoreSoftlyUsingRule() {Score score Score.scoreBuilder().withValue(11).withCombination(dice(1, 1, 3, 4)).withReminder(dice(6)).build();softAssertions.assertThat(score.getValue()).as(Has score).isEqualTo(8);softAssertions.assertThat(score.getCombination()).as(Has combination).isEqualTo(dice(1, 1, 3, 3));softAssertions.assertThat(score.getReminder()).as(Has reminder).isEqualTo(dice(5)); } 我们不仅不需要记住调用assertAll()而且还可以在IntelliJ的比较编辑器中看到潜在的失败 自定义 为了提高分数验证的可读性和可重用性我们可以创建一个自定义断言以便可以按以下方式使用它 Test public void verifiesScoreSoftlyWithCustomAssertion() {Score score Score.scoreBuilder().withValue(11).withCombination(dice(1, 1, 3, 4)).withReminder(dice(6)).build();SoftScoreAssertion.assertThat(score).hasValue(8).hasCombination(dice(1, 1, 3, 3)).hasReminder(dice(5)).assertAll(); } SoftScoreAssertion使用SoftAssertions 因此我们仍然会立即看到所有断言错误。 和代码 class SoftScoreAssertion extends AbstractAssertSoftScoreAssertion, Score {private SoftAssertions softAssertions new SoftAssertions();protected SoftScoreAssertion(Score actual) {super(actual, SoftScoreAssertion.class);}public static SoftScoreAssertion assertThat(Score actual) {return new SoftScoreAssertion(actual);}public SoftScoreAssertion hasValue(int scoreValue) {isNotNull();softAssertions.assertThat(actual.getValue()).as(Has score).isEqualTo(scoreValue);return this;}public SoftScoreAssertion hasReminder(ListDice expected) {isNotNull();softAssertions.assertThat(actual.getReminder()).as(Has reminder).isEqualTo(expected);return this;}public SoftScoreAssertion hasCombination(ListDice expected) {isNotNull();softAssertions.assertThat(actual.getCombination()).as(Has combination).isEqualTo(expected);return this;}Overridepublic SoftScoreAssertion isNotNull() {softAssertions.assertThat(actual).isNotNull();return this;}public void assertAll() {this.softAssertions.assertAll();} }资源资源 http://joel-costigliola.github.io/assertj/assertj-core-features-highlight.html#soft-assertions https://github.com/joel-costigliola/assertj-core/wiki/Creating-specific-assertions 源代码 可以在我在GitHub上的unit-testing-demo项目中找到本文的源代码 https : //github.com/kolorobot/unit-testing-demo 。 翻译自: https://www.javacodegeeks.com/2015/09/assertjs-softassertions-do-we-need-them.htmlassertj
http://www.sadfv.cn/news/391557/

相关文章:

  • 怎么查看网站的域名wordpress 修改固定链接 404
  • 做桂林网站的图片大全济南网站建设流程
  • 网站开发 asp.net 还要学什么网络平台企业
  • 如何做自己的游戏网站永久免费素材网站
  • 做网站龙头淄博展厅设计公司
  • 网站开发qq头像2017国外优秀网站模版
  • 北外新闻行业门户网站建设广州市做app的公司地址
  • 专业做中文网站镇江市建设工程网站
  • 可以做彩票网站的工作室网站建设教程大全 百度网盘
  • 国外网站如何做seo深圳返利网站建设
  • 建设审批网站查询北京设计机构
  • 劳务输送网站建设方案广东微信网站建设哪家专业
  • 三网合一网站源码下载wordpress 乱码
  • 深圳知名网站建设哪家好页游网
  • 制作网站公司 英语网站首页宁波网站建设公司哪个好
  • 保定有哪些做网站的地方电子商务网站建设作业总结
  • 什么做书籍的网站好wordpress订阅 rss
  • 网站注册时间网站推广公司招聘
  • 桐庐县建设局网站小学网站建设成都
  • 网站颜色搭配实例高端网站建设jm3q
  • 前几年做那些网站能致富广州市建设集团网站
  • 做网站 学什么元隆盛建设集团有限公司网站
  • 店铺外卖网站怎么做网站建设网站图片放哪个
  • 网站建设市场调研报告杭州的服装网站建设
  • 网站后台管理器怎么做东莞网站运营知名乐云seo
  • 广州市移动网站建设服务公司35互联做网站好吗
  • 衡阳北京网站建设如何增加百度收录
  • 设计美观网站有哪些网站建设 天秀网络
  • 做一个商品网站多少钱asp网站模板源码免费无限下载
  • 做外贸的国际网站有哪些内容ps里新建网站尺寸怎么做