Issues running both TestNG and Junit tests from a single command line test filter

I am learning gradle and figure that I’m doing something wrong here as I’m trying to execute both my TestNG and JUnit tests in my nested project(s) using a single filter command. I’m looking to connect it to CI where filters can be used to run tests by name, regardless of whether the test uses TestNG or JUnit.
I believe that I’ve found some code to do this, but am getting unexpected results when invoking the test task. Please see actual and expected results below:

This is what I have in my build.gradle for my subproject:

task testNG (type: Test) {
	useTestNG()
}

test {
	useJUnit()
	dependsOn testNG
    maxParallelForks=50
  }

When I execute my filters to test it, though, I get some unexpected results. I’m expecting that when I tell it to run a testNG test, it will execute them and report back on the failures. Same expectation when I tell it to run a JUnit test. However, instead, it won’t find the TestNG test unless I either:

  1. Call the TestNG task directly (undesirable) or
  2. Call the TestNG task directly and then immediately afterwards, trigger a filter that covers both JUnit and TestNG trigger.

Observe:

$ ./gradlew :my-webdriver-tests:test --tests com.examplepackage.test.ExampleJunitTest
com.examplepackage.test.ExampleJunitTest > myFailingTest PASSED
com.examplepackage.test.ExampleJunitTest > myPassingTest PASSED

$ ./gradlew :my-webdriver-tests:test --tests com.examplepackage.test.Example*
:my-webdriver-tests:test
com.examplepackage.test.ExampleJunitTest > myFailingTest PASSED
com.examplepackage.test.ExampleJunitTest > myPassingTest PASSED

$ ./gradlew :my-webdriver-tests:test --tests com.examplepackage.test.ExampleTestNGTest
> No tests found for given includes: [com.examplepackage.test.ExampleTestNGTest]

But if I first execute the TestNG task directly…

$ ./gradlew :my-webdriver-**tests:testNG** --tests com.examplepackage.test.ExampleTestNGTest
:my-webdriver-tests:testNG
Gradle suite > Gradle test > com.examplepackage.test.ExampleTestNGTest.myFailingTest PASSED
Gradle suite > Gradle test > com.examplepackage.test.ExampleTestNGTest.myPassingTest PASSED
--------------------------------------------------------------------
|  Results: SUCCESS (2 tests, 2 successes, 0 failures, 0 skipped)  |
--------------------------------------------------------------------

…and then call the one to trigger both types, it works as expected, but only for the ONE command that immediately follows my direct TestNG task command, then they start failing again…

$ ./gradlew :my-webdriver-tests:test --tests com.examplepackage.test.Example*
:my-webdriver-tests:testNG
Gradle suite > Gradle test > com.examplepackage.test.ExampleTestNGTest.myFailingTest PASSED
Gradle suite > Gradle test > com.examplepackage.test.ExampleTestNGTest.myPassingTest PASSED
--------------------------------------------------------------------
|  Results: SUCCESS (2 tests, 2 successes, 0 failures, 0 skipped)  |
--------------------------------------------------------------------
:my-webdriver-tests:test
com.examplepackage.test.ExampleJunitTest > myFailingTest PASSED
com.examplepackage.test.ExampleJunitTest > myPassingTest PASSED
--------------------------------------------------------------------
|  Results: SUCCESS (2 tests, 2 successes, 0 failures, 0 skipped)  |
--------------------------------------------------------------------

What’s wrong here, and/or how can I set this project up to be able to run either junit or testNG via the command line, without the user having to specify the tech being used?

Sounds you have the same problem: Options for a dependent task