Internals of Test Classes compatibility with Test Framework

Hi,

A bit Context : The build task runs test task as well present in the tasks list to be executed. Since the default testFramework is junit4, Gradle searches for compatible classes and executes them further. If the test classes are junit5 based then it skips.

How does Gradle detects the actual classes to be executed or respective framework runner would identify that?

Want to build logic inside the Custom Gradle Plugin to detect if the default definition of test task would execute any classes further or not. Will execute a custom task on the basis of that.

task junitTest(type: Test) {
    useJUnitPlatform()
}

vs

test {}

where test classes are junit5 runner based.

If you don’t know whether you have JUnit 4 or Jupiter tests or both, just configure the task to always use JUnit platform and add the Jupiter and the vintage engines. The latter runs JUnit 4 tests on JUnit platform.

User would’ve already set the TestFramework, so don’t want to reconfigure that.

Ok, then let me ask you to take a step back, as it might be an XY problem.
What do you want to achieve?
What is your use-case?
What would that task do?