You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改JQassistant Cypher规则识别AssertJ的assert*断言方法

Fix JQassistant Rule to Recognize AssertJ Assertions

Got it, let's get that JQassistant rule sorted so it stops flagging test methods using AssertJ's assertThat() as "no assertions present". Here's the adjusted Cypher query and breakdown of the fix:

Modified Cypher Rule

MATCH (c:Type:Class)-[:DECLARES]->(m:Method:JunitTestMethod),
      (m)-[:INVOKES*..10]->(assert:Method)
WHERE assert.name STARTS WITH 'assert'
WITH m, count(assert) as assertionCount
WHERE assertionCount = 0
RETURN m.fullName as TestMethodWithoutAssertions

Key Changes Explained

  1. Added a flexible assertion method filter: The WHERE assert.name STARTS WITH 'assert' clause ensures we capture any method whose name starts with "assert". This covers:

    • Traditional JUnit assertions like assertEquals(), assertTrue()
    • AssertJ's assertThat() (since it follows the "assert*" naming pattern)
    • Any custom assertion methods you might have that use the standard "assert" prefix
  2. Eliminates hardcoded method limitations: If your original rule only matched specific JUnit assertion method names, this change makes it flexible enough to support all assertion libraries that adhere to the common "assert" naming convention.

Optional: Narrow to Known Assertion Classes (Edge Case Fix)

If you want to avoid accidental matches with non-assertion methods that start with "assert" (a rare scenario), you can add an extra condition to limit matches to trusted assertion libraries:

MATCH (c:Type:Class)-[:DECLARES]->(m:Method:JunitTestMethod),
      (m)-[:INVOKES*..10]->(assert:Method)
WHERE assert.name STARTS WITH 'assert'
  AND assert.declaringType.name IN [
    'org.junit.Assert',
    'org.assertj.core.api.Assertions',
    'org.assertj.core.api.AbstractAssert'
  ]
WITH m, count(assert) as assertionCount
WHERE assertionCount = 0
RETURN m.fullName as TestMethodWithoutAssertions

This ensures we only count assertions from established libraries, not random utility methods that happen to start with "assert".

内容的提问来源于stack exchange,提问作者skpraveen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:58:31