如何在Coverity Connect分析结果中排除Java单元与集成测试?
Got it, let's work through this Coverity filtering problem. Since Coverity only supports simple glob patterns (* for any character sequence, ? for single characters) and doesn't handle regex features like negative lookarounds, we need straightforward workarounds tailored to its capabilities.
Option 1: Exclude by Filename Pattern (Perfect for Your Case)
Your integration tests all have "Test" in their filenames, and you already used -Dmaven.skip.test=true to skip unit test compilation (so Coverity isn't scanning those anyway). Here's how to exclude the remaining integration tests:
- In Coverity's filtering interface, create a new Exclude Rule.
- Set the rule type to
File. - Use the pattern
*Test*.javaas the match criteria.
This will catch every Java file with "Test" in its name—exactly your integration tests—since Coverity uses * to match any characters before or after "Test".
Option 2: Exclude by Directory (More Precise If Tests Are Organized)
If your integration tests live in a dedicated directory (like src/integration-test/java or even the standard src/test/java if unit tests are already skipped), you can exclude the entire directory tree:
- Create a new Exclude Rule with type
File. - Use a path pattern like
src/integration-test/java/**/*.java(the**matches any subdirectory).
This is cleaner if your test files follow a consistent directory structure, as it avoids relying on filename conventions.
Why Your Original Regex Didn't Work
Coverity doesn't support full regular expressions—its pattern matching is limited to basic glob wildcards. Syntax like !?(Test) (negative lookarounds) isn't recognized here, which is why your initial attempt failed. The glob patterns above are the only supported way to filter files.
内容的提问来源于stack exchange,提问作者LoreV




