Skip to content

test: avoid polluting test classpaths with sample dependencies to be scanned#8267

Merged
jeremylong merged 1 commit intodependency-check:mainfrom
chadlwilson:dont-pollute-test-classpaths
Feb 2, 2026
Merged

test: avoid polluting test classpaths with sample dependencies to be scanned#8267
jeremylong merged 1 commit intodependency-check:mainfrom
chadlwilson:dont-pollute-test-classpaths

Conversation

@chadlwilson
Copy link
Collaborator

@chadlwilson chadlwilson commented Jan 31, 2026

Description of Change

As mentioned in #8254 (comment) currently the XML testing is a bit unreliable and difficult to debug because xerces and xml-apis dependencies are being pulled down and used during testing due to their inclusion within artifacts that are intended just for use as "sample" artifacts to scan using ODC code.

Other than the risk of classpath clashes, when code uses JDK ServiceLoader mechanisms (such as the XML APIs), I think this can cause production code to be tested with an environment unrepresentative of a real deployment.

We can address this by creating a maven execution that copies dependencies as artifacts to a known test resource location rather than adding to the actual test/integration test classpaths.

Minor tweaks

  • cleaned up the assertions for known errors during engine integration test (which scans these dependencies) to a minimal set which are easier to debug
  • removed an ineffective Junit assumption when a test resource isn't available (already NPEing early in the code). These should probably fail the tests anyway.

Related issues

Have test cases been added to cover the new functionality?

yes

…scanned

Signed-off-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
@boring-cyborg boring-cyborg bot added core changes to core tests test cases labels Jan 31, 2026
@chadlwilson chadlwilson requested a review from Copilot January 31, 2026 16:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses test environment pollution by changing how sample dependencies are made available during testing. Instead of adding test-scoped dependencies to the classpath (which can cause conflicts with JDK ServiceLoader mechanisms), the PR uses Maven's dependency plugin to copy artifacts to a dedicated maven-lib test resource directory.

Changes:

  • Refactored Maven build configuration to copy sample artifacts to target/test-classes/maven-lib instead of adding them as test-scoped dependencies
  • Updated all test file paths to reference the new maven-lib/ subdirectory
  • Streamlined integration test error handling with more maintainable assertions

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/pom.xml Replaced test-scoped dependencies and copy-dependencies execution with a targeted copy execution that places artifacts in maven-lib subdirectory
core/src/test/java/org/owasp/dependencycheck/BaseTest.java Removed JCS logging setup and improved resource loading methods to use Objects.requireNonNull instead of JUnit assumptions
core/src/test/java/org/owasp/dependencycheck/EngineIT.java Refactored exception handling in integration test to use streams and assertions, replacing Set-based error filtering
core/src/test/java/org/owasp/dependencycheck/xml/suppression/SuppressionRuleTest.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/xml/suppression/SuppressionParserTest.java Removed commented-out code
core/src/test/java/org/owasp/dependencycheck/reporting/ReportGeneratorIT.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/dependency/DependencyTest.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/data/update/NvdApiDataSourceTest.java Removed unused import and annotation from method signature
core/src/test/java/org/owasp/dependencycheck/data/nvdcve/DriverLoaderTest.java Removed commented-out code
core/src/test/java/org/owasp/dependencycheck/analyzer/VulnerabilitySuppressionAnalyzerIT.java Updated resource path to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/JarAnalyzerTest.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/HintAnalyzerTest.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/FileNameAnalyzerTest.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/DependencyMergingAnalyzerTest.java Updated resource path to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/CpeSuppressionAnalyzerIT.java Updated resource path to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/CPEAnalyzerIT.java Updated resource paths to include maven-lib/ prefix
core/src/test/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzerIT.java Updated resource path to include maven-lib/ prefix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@jeremylong jeremylong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeremylong jeremylong added this to the 12.2.1 milestone Jan 31, 2026
@jeremylong jeremylong merged commit c980cc9 into dependency-check:main Feb 2, 2026
15 of 16 checks passed
@chadlwilson chadlwilson deleted the dont-pollute-test-classpaths branch February 2, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core changes to core tests test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants