JUnit Categories defined but declared JUnit version does not support Categories

(Pani Kumar) #1

I am using JUnit 4.11 and I get this error when I try running tests. Just wondering where is this declared JUnit version ?

task myTests(type: Test, description: ‘Runs tests’) {

useJUnit {

includeCategories ‘org.gradle.junit.SomeCategory’

} }

(Peter Niederwieser) #2

Which error do you get? And can you elaborate on your question? The JUnit version used is determined by the version of the JUnit dependency that you declare for the ‘test’ configuration.

(Pani Kumar) #3

Peter: Thank you for the reply.

What I am trying to achieve is to run a specific Junit Category of tests.

Please find below error message with partial stack trace.

  • What went wrong: Execution failed for task ‘:myTests’. > JUnit Categories defined but declared JUnit version does not support Categories.

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

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

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:69)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecute(ExecuteActionsTaskExecuter.java:46)

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec uter.execute(PostExecutionAnalysisTaskExecuter.java:35)

at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskE xecuter$1.run(CacheLockReleasingTaskExecuter.java:35)

at org.gradle.internal.Factories$1.create(Factories.java:22)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def aultCacheAccess.java:179)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def aultCacheAccess.java:232)

at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning Operation(DefaultPersistentDirectoryStore.java:142)

at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStat eCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)

at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskE xecuter.execute(CacheLockReleasingTaskExecuter.java:33)

Here is the complete code:

ext {

versions = [

junit: ‘4.11’

] }

dependencies {

“junit:junit:${versions.junit}”, }

task myTests(type: Test, description: ‘Run s Tests’) {

useJUnit {

includeCategories ‘org.gradle.junit.SomeCategory’

} }

Please let know if you need more details like complete stack trace or something that would help. Thanks

(Peter Niederwieser) #4

You forgot to declare the scope (e.g. ‘test’) in the dependencies block.

(Pani Kumar) #5

Thanks Peter. That helped. :slight_smile: