[Test Filtring] How to write 'Custom Test Task' for Play/Scala Project


(Ahmet Türk) #1

Hi all,
I am trying to write custom test task to separate tests like UnitTests, FunctionalTests etc.
I have name structure like *UnitSpec, *FunSpec, *IntegrationSpec at the end of the file name.
I can simply run gradle testPlayBinary --test '*UnitSpec' to run only UnitSpecs under the test folder.

What I want to do is that I want to filter test in build.gradle with custom test task.For instance gradle runUnitSpecs.

I am using Play Framework and all my test classes are under the “test” folder on the root.
I am using Play my build.gradle.
I tried a couple of code but could not get it work right. I feel like all the examples on the internet I found for java but it was just a filtring and it should work with play, scala or whatever.

For instance, I tried that one and it gives me the error “No tests found for given includes: [*UnitSpec]”

task runUnitSpecs(type: Test) {
filter {
    includeTestsMatching "*UnitSpec"
}

description = "Runs Automation Tests"
testClassesDir = file("$rootDir/test")
classpath += sourceSets.main.runtimeClasspath

}