验证已在Assertj中调用了断言 [英] Verify that assertions have been called in Assertj

查看:118
本文介绍了验证已在Assertj中调用了断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读使用Assertj验证结果的测试类. 有时,我发现一个没有断言的assertThat.

I'm reading through test classes that use Assertj to verify results. Occasionally, I've spotted an assertThat without assertions.

assertThat(object.getField());

是否可以在开发周期中的某个位置识别这些类?我的第一个猜测是使用自定义的Sonar规则.尽管我看不到如何定义该方法后应带有断言(方法返回void?)的方法.

Is it possible to identify these classes somewhere in the development cycle? My first guess would be to use a custom Sonar rule. Although I don't see how I should define that this method should be followed by an assertion (a method returning void?).

推荐答案

SonarJava具有规则S2970声明应完整",该规则可以检测assertThat而无需声明AssertJ,Fest和Truth.

SonarJava is having the rule S2970 "Assertions should be complete" that can detect assertThat without assertions for AssertJ, Fest and Truth.

请参阅: https://rules.sonarsource.com/java/RSPEC-2970

这篇关于验证已在Assertj中调用了断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆