A test case without assertions ensures only that no exceptions are thrown. Beyond basic runnability, it ensures nothing about the behavior of thecode under test.
This rule raises an exception when no assertions from any of the following known frameworks are found in a test:
Furthermore, as new or custom assertion frameworks may be used, the rule can be parametrized to define specific methods that will also beconsidered as assertions. No issue will be raised when such methods are found in test cases. The parameter value should have the following format<FullyQualifiedClassName>#<MethodName>, where MethodName can end with the wildcard character. For constructors,the pattern should be <FullyQualifiedClassName>#<init>.
A test case without assertions ensures only that no exceptions are thrown. Beyond basic runnability, it ensures nothing about the behavior of thecode under test.
This rule raises an exception when no assertions from any of the following known frameworks are found in a test:
org.springframework.test.web.servlet.ResultActions.andExpect()
Furthermore, as new or custom assertion frameworks may be used, the rule can be parametrized to define specific methods that will also beconsidered as assertions. No issue will be raised when such methods are found in test cases. The parameter value should have the following format
<FullyQualifiedClassName>#<MethodName>
, whereMethodName
can end with the wildcard character. For constructors,the pattern should be<FullyQualifiedClassName>#<init>
.Example:
com.company.CompareToTester#compare*,com.company.CustomAssert#customAssertMethod,com.company.CheckVerifier#<init>
.Noncompliant Code Example
Compliant Solution
Example when
com.company.CompareToTester#compare*
is used as parameter to the rule.File Path: webgoat-lessons/jwt/src/test/java/org/owasp/webgoat/jwt/JWTVotesEndpointTest.java:118
Mitigation: Add at least one assertion to this test case.
https://preprod.armorcode.ai/#/findings/5407951