-Dtest.single doesn't work when test tasks is in buildSrc

After we defined custom task class for selenium test task and put it into buildSrc, the -DseleniumTest.single option stopped working. It looks somewhat similar to http://issues.gradle.org/browse/GRADLE-1553 but not exactly. If we set -DseleniumTest.single=MyTest, we get “Could not find matching test for pattern: MyTest”, when we follow the GRADLE-1553 workaround specifying -Dsubproject.seleniumTest.single=MyTest then all tests are executed and “single” is ignored. Also it’s not clear to me, but it seems that GRADLE-1553 is about test IN buildSrc, so tests for the custom class, and we talk about normal tests executed by the custom task

this is our task

import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.TaskAction
    public class TestNGTask extends Test {
    String[] includedGroups = []
    String[] excludedGroups = []
      @TaskAction
    def runTests() {
                createConfiguration = { ig, eg ->
            return {
                includeGroups ig
                excludeGroups eg
                useDefaultListeners = false
                listeners << 'org.uncommons.reportng.HTMLReporter'
            }
        }
        options {
            jvmArgs "-Drun.mode=test"
            useTestNG(createConfiguration(includedGroups, excludedGroups))
            afterTest printTestStatus
        }
        executeTests()
    }
          def includeGroups(String... includeGroups) {
        includedGroups = includeGroups
    }
      def excludeGroups(String... excludeGroups) {
        excludedGroups = excludeGroups
    }
          def printTestStatus = { desc, result ->
         println "Test ${result.resultType} ${desc.name} [${desc.className}] in ${(result.endTime-result.startTime)/1000}s"
    }
}

and it’s used in subproject this way

task seleniumTest(type: TestNGTask) {
    testReportDir = getReportsDir(workingDir, "selenium")
    includeGroups 'selenium'
}

could you advise something?

This is the same as GRADLE-1553.

You’re missing the leading “:” prefix on the task path. So you need to invoke with as…

gradle -D:subproject:seleniumTest.single=MyTest

I’ll update the instructions on the ticket.

We’re aware that this is a little cumbersome, and will be improved in the future.

Hi Luke, thanks for the quick response, unfortunately this doesn’t work for me either when I run

gradle :subproject:seleniumTest -D:subproject:seleniumTest.single=MyTest

I get Could not find matching test for pattern: MyTest when I run (dot instead of colon between project and task name)

gradle :subproject:seleniumTest -D:subproject.seleniumTest.single=MyTest

then single is ignored and all tests are run (as without colon before subproject)

What’s the full error message you get after:

gradle :subproject:seleniumTest -D:subproject:seleniumTest.single=MyTest

?

so it’s like that, after command

gradle :tad:seleniumTest -D:tad:seleniumTest.single=LoginTest --stacktrace

I got … :tad:seleniumTest

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:tad:seleniumTest’. Cause: Failed to notify test listener. Cause: Could not find matching test for pattern: LoginTest

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:tad:seleniumTest’.

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:71)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:48)

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)

at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)

at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)

at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)

at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)

at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)

at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)

at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:237)

at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:167)

at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:160)

at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:78)

at org.gradle.execution.TaskNameResolvingBuildExecuter.execute(TaskNameResolvingBuildExecuter.java:113)

at org.gradle.execution.DelegatingBuildExecuter.execute(DelegatingBuildExecuter.java:54)

at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:158)

at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:112)

at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:80)

at org.gradle.launcher.RunBuildAction.execute(RunBuildAction.java:41)

at org.gradle.launcher.RunBuildAction.execute(RunBuildAction.java:27)

at org.gradle.launcher.ExceptionReportingAction.execute(ExceptionReportingAction.java:32)

at org.gradle.launcher.ExceptionReportingAction.execute(ExceptionReportingAction.java:21)

at org.gradle.launcher.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:219)

at org.gradle.launcher.CommandLineActionFactory$WithLoggingAction.execute(CommandLineActionFactory.java:203)

at org.gradle.launcher.Main.execute(Main.java:55)

at org.gradle.launcher.Main.main(Main.java:40)

at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:46)

at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:28)

at org.gradle.launcher.GradleMain.main(GradleMain.java:24) Caused by: org.gradle.listener.ListenerNotificationException: Failed to notify test listener.

at org.gradle.messaging.dispatch.BroadcastDispatch.dispatch(BroadcastDispatch.java:97)

at org.gradle.messaging.dispatch.BroadcastDispatch.dispatch(BroadcastDispatch.java:32)

at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:75)

at $Proxy23.afterSuite(Unknown Source)

at org.gradle.api.internal.tasks.testing.results.TestListenerAdapter.completed(TestListenerAdapter.java:46)

at org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor.completed(StateTrackingTestResultProcessor.java:53)

at org.gradle.api.internal.tasks.testing.results.AttachParentTestResultProcessor.completed(AttachParentTestResultProcessor.java:51)

at org.gradle.api.internal.tasks.testing.processors.TestMainAction.run(TestMainAction.java:48)

at org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter.execute(DefaultTestExecuter.java:75)

at org.gradle.api.tasks.testing.Test.executeTests(Test.java:332)

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:158)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:93)

at TestNGTask_Decorated.invokeMethod(Unknown Source)

at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:129)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$2.execute(AnnotationProcessingTaskFactory.java:127)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:63)

… 28 more Caused by: org.gradle.api.GradleException: Could not find matching test for pattern: LoginTest

at org.gradle.api.plugins.JavaBasePlugin$12.afterSuite(JavaBasePlugin.java:257)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

at org.gradle.messaging.dispatch.BroadcastDispatch.dispatch(BroadcastDispatch.java:88)

… 44 more

BUILD FAILED

So this is a different problem. That output says that the right task has been targetted, but it indeed can’t find anything matchin that name.

One thing to try would be to temporarily rename the “buildSrc” dir to take it out of the equation, then use the same command. It should fail in the same way.

It’s hard to say why “LoginTest” can’t be found, but try to get it working without buildSrc being in the way first.

well, that is a bit of a problem as the test task class is in the buildSrc (see my first post), so it is a part of equation

before we defined custom class for that, running single test worked fine

Try moving the custom test task back into the build.gradle file temporarily.

Your test task is receiving the .single argument, but it can’t find anything that matches that. This is almost certainly due to configuration of the task.

I’m unsure what else to advise without having a sample that exhibits the problem that I can play with.

Thanks, if I manage to create a test case, how could I send it to you? I can’t see any way to attach a file on the forum

The best thing to do would be to create an issue at http://issues.gradle.org and attach it there.

I created GRADLE-1864, but I’m having problems with attaching my testcase. After I choose a file in filesystem and click “Attach” button I get error “Please indicate the file you wish to upload”. What could be wrong?

ok, I managed to attach it - it didn’t work with Firefox but did with IE

The problem is that your custom @TaskAction is being called after the executeTest() action from the Test base class. You need to rewrite your custom task to override the executeTests() method.

public class TestNGTask extends Test {

String[] includedGroups = []

String[] excludedGroups = []

@TaskAction

void executeTests() {

createConfiguration = { ig, eg ->

return {

includeGroups ig

excludeGroups eg

useDefaultListeners = false

listeners << ‘org.uncommons.reportng.HTMLReporter’

}

}

options {

jvmArgs “-Drun.mode=test”

useTestNG(createConfiguration(includedGroups, excludedGroups))

afterTest printTestStatus

}

super.executeTests()

}

def includeGroups(String… includeGroups) {

includedGroups = includeGroups

}

def excludeGroups(String… excludeGroups) {

excludedGroups = excludeGroups

}

def printTestStatus = { desc, result ->

println “Test ${result.resultType} ${desc.name} [${desc.className}] in ${(result.endTime-result.startTime)/1000}s”

} }

thanks! it works now

I only wonder … if method executeTests() were called twice, then why tests weren’t executed twice?

It wasn’t executed twice, it was executed before your @TaskAction. There can be many task actions.