Refactor reflection responsibilities across TestNG modules

Open
#3,371 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
testing

Research direction

Start by reading ReflectionRecipes, ReflectionHelper, ClassHelper, and the testng-reflection-utils and testng-core module boundaries. The first proposed slice is a type-assignability utility with exhaustive primitive-conversion tests, followed by delegation from ReflectionRecipes. Done means the utility owns generic type logic while existing behavior remains covered and the broader migration plan is agreed.

Written by the indexing model from the issue text.

Description

area: parameters area: public api aspect: architecture effort: high priority: low status: confirmed triage: ai-reviewed type: epic

Context

While working on #3362, I noticed that reflection-related responsibilities are currently spread across three modules:

  • "testng-reflection-utils" with "ReflectionHelper"
  • "testng-core" with "ReflectionRecipes" and the method matchers
  • "testng-core-api" with "ClassHelper"

I think this makes the boundaries difficult to understand and has led to generic Java reflection/type logic being mixed with TestNG-specific parameter matching and injection logic.

For example, "ReflectionRecipes" currently mixes:

  • generic type assignability and primitive widening;
  • method/constructor parameter helpers;
  • DataProvider argument matching;
  • TestNG native parameter injection.

Similarly, "ClassHelper" mixes generic class loading/method discovery with TestNG-specific factory and XML-related behavior.

Proposed direction

I would like to make "testng-reflection-utils" the single owner of generic Java reflection utilities.

The rule would roughly be:

«"testng-reflection-utils" knows what Java allows; "testng-core" knows what TestNG wants to do with it.»

"testng-reflection-utils"

Keep all generic, TestNG-independent functionality here, for example:

org.testng.internal.reflect
├── ReflectionHelper
├── TypeUtils / TypeAssignability
└── ClassLoadingHelper

This would include:

  • type assignability;
  • primitive/wrapper handling;
  • primitive widening rules;
  • class loading;
  • method hierarchy/discovery;
  • generic annotation/reflection helpers.

Ideally, this module should not depend on TestNG domain types.

"testng-core"

The current classes under "org.testng.internal.reflect" such as:

DataProviderMethodMatcher
DirectMethodMatcher
ArrayEndingMethodMatcher
InjectableParameter
MethodMatcher*

are not really generic reflection utilities. They implement TestNG parameter matching/injection semantics.

I would move them to something like:

org.testng.internal.parameters

and split the TestNG-specific parts of "ReflectionRecipes" into concepts such as:

ParameterMatcher
ParameterInjector

"ReflectionRecipes" could then disappear entirely.

"testng-core-api"

"ClassHelper" should probably not be moved as-is either.

Its generic parts (class loading, method discovery, etc.) could move to "testng-reflection-utils", while TestNG-specific operations such as factory discovery or "XmlSuite"/"XmlTest" handling remain in "testng-core-api" under more specific classes.

Since "ClassHelper" is public even though it is under "org.testng.internal", we could keep delegating/deprecated methods temporarily if compatibility is a concern.

Suggested incremental migration

I would avoid doing this as one large refactoring.

  1. Introduce a small type-assignability utility in "testng-reflection-utils", with exhaustive primitive conversion tests, and make "ReflectionRecipes" delegate to it.
  2. Extract "exactMatch", "lenientMatch" and "matchArrayEnding" into parameter-matching code in "testng-core".
  3. Extract "filter", "inject" and "canInject" into parameter-injection code.
  4. Remove "ReflectionRecipes".
  5. Split the generic responsibilities out of "ClassHelper".
  6. Eventually make "org.testng.internal.reflect" belong exclusively to "testng-reflection-utils".

This should give us a clearer module boundary without introducing another reflection library or requiring a large rewrite.

@krmahadevan, what do you think about this direction?


Drafted by ChatGPT under Julien's supervision.

Dominant language
Java
Stars
2.1k
Forks
1k
Avg merge
2d 23h
Merged PRs (30d)
38

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testng-team/testng

All issues in testng-team/testng

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.