useTestNG() - why is it required?

Why is it necessary to use useTestNG() call in the test task configuration, why can’t gradle discover the test framework to use itself? I think that’s what surefire does, could it be done here as well?

One reason is that the classes folder passed to the test task could contain both JUnit and TestNG task, but a single Test task can’t execute both. Also, Gradle usually finds test classes by scanning the classes folder rather than by imposing a class naming pattern, and scanning for both TestNG and JUnit tests would take more time. Lastly, ‘useTestNG { … }’ is also used for specifying TestNG specific configuration options.

There have been discussions about changing the current model. For example, one idea was to have separate JUnit and TestNG tasks. But the alternatives discussed have their own set of drawbacks, and what we have today works quite well in practice. Hence this topic is not a priority.