Make a complete copy of Test task

A plugin I am working on needs to make copies of the main Test task. Most of the copying is easy enough. But there are a few things I am having difficulty with and hoping to get some help.

The main test task in my test project is using JUnit 5 and so needs to enable useJUnitPlatform(). However, I am missing how to transfer that bit of information from the main test task to my copy - I need to determine the framework used by the main test task and make the copy use the same.

The test copies do not run any tests. Hopefully that is simply due to the framework. Otherwise, is Test#setTestClassesDirs all I need to do in order for the tests to be found?

Is there any real downside to simply enabling all of the platforms in my copy?

1 Like

You could probably do

TestFrameworkOptions options = testTask.getOptions();
if (options instanceof TestNGOptions) {
} else if (options instanceof JUnitOptions) {
} else if (options instanceof JUnitPlatformOptions) {

See TestFrameworkOptions

1 Like

Thanks for the idea Lance. That will definitely work.

Any thoughts on whether enabling all of the frameworks is “bad” in some way?

I’d say not possible rather than bad

Interestingly, it works in my trials. I cannot explain why looking through the code. I agree with you it seems like it should not. It seems there should only be able to be one at a time. Though stepping back, that seems odd as well - that a project cannot mix JUnit and TestNG tests.

It’s possibly last one wins, so if you set all three, the first two don’t have any effect

I think TestNG is an extension of junit and supports junit tests. So by using testNG you can have a mix of both

I would tend to agree looking at the code. What is odd though is that the one I need in this particular scenario is done first. I need JUnit 5 (platform) and do:


So it is interesting that copy.useJUnitPlatform() wins.

That might be true wrt test-ng. Never use it