Execute a few tests from terminal and Junit 5 using

37 views
Skip to first unread message

Gordon Freeman

unread,
May 11, 2020, 6:52:38 AM5/11/20
to Geb User Mailing List
Hi, guys! I need your advice.

I have 2 test folders:
\src\test\groovy\tests\ui
\src\test\groovy\tests\api

And have 2 tasks in Gradle:
task uiTest(type: Test) {
    doFirst
{
        include
"**/ui/${System.getProperty("testPackage", "")}"
        exclude
"**/api/*"
   
}
    maxParallelForks
= 4
    forkEvery
= 4
    testLogging
.showStandardStreams = true
}

task apiTest(type: Test) {
    doFirst
{
        include
"**/api/${System.getProperty("testPackage", "")}"
        exclude
"**/ui/*"
   
}
    maxParallelForks
= 4
    forkEvery
= 4
    testLogging
.showStandardStreams = true
}

I can easily execute one particular test OR all tests in one folder without any execution issues, example for ui tests:
gradlew.bat "-DtestPackage=/" clean uiTest -b build.gradle
gradlew
.bat "-DtestPackage=/Ui1Spec*" clean uiTest -b build.gradle


So, I have 2 questions:
1. How can I execute more than 1 test simultaneously for one testPackage, but not all tests from testPackage?
For example: in
 '\src\test\groovy\tests\ui'
I have 100 tests, but I need to execute only 'Ui1Spec', 'Ui5Spec', 'Ui17Spec' and 'UiRegression78Spec'

2. How can I execute tests by Junit5 tag? 
Let me explain: previously I was working on another framework and we used Selenide+JUnit5, it was very easy to mark test by annotation
@Tag('regression')
and then execute only tests which were marked:
 '-Dtag=regression'

I was trying to create gradle task with this closure:
 useJUnitPlatform {
        includeTags
'regression' //or System.getProperty('tag') to make it generic
   
}

Found it here but it doesn`t work with Spock/Geb, maybe because test classes doesn`t contain 'Test' suffix? 

FYI my dependencies: 

gebVersion = '3.4'
junitVersion
= '5.6.1'
spockVersion
= '1.2-groovy-2.5'
groovyVersion
= '2.5.10'
compile
"org.gebish:geb-spock:$gebVersion"
compile
"org.codehaus.groovy:groovy-all:$groovyVersion"
compile
"org.codehaus.groovy:groovy-dateutil:$groovyVersion"
compile
"org.codehaus.groovy:groovy-all:$groovyVersion"
compile
"org.codehaus.groovy:groovy-dateutil:$groovyVersion"
testImplementation
("org.junit.jupiter:junit-jupiter:$junitVersion")
testCompile
("org.spockframework:spock-core:$spockVersion") {
        exclude
group: "org.codehaus.groovy"
   
}

Thanks in advance! 

Marcin Erdmann

unread,
May 13, 2020, 4:06:53 PM5/13/20
to geb-...@googlegroups.com
Gordon,

For 1., why don't you simply use built in test filtering provided by Gradle Test task?


For 2., I don't think Spock 1.2 supports JUnit5. Why don't you use JUnit categories instead as described at the beginning of https://docs.gradle.org/current/userguide/java_testing.html#test_grouping?

Marcin

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/c2449a17-05b7-45d4-9e0d-4af8bf5208bd%40googlegroups.com.

Gordon Freeman

unread,
May 13, 2020, 5:49:58 PM5/13/20
to Geb User Mailing List
Hi, Marcin! 
Thanks for your reply!

For 1. I didn`t know about this option, you really help me. I just tried to run a few scripts and it works.
For 2. I found this article https://blog.jdriven.com/2018/10/combining-spock-junit-5-tests/ so, Junit5 and Spock 1.2 should work together.
I`m not familiar with categories in Junit, should I somehow mark tests to some categories before create Gradle task?

To unsubscribe from this group and stop receiving emails from it, send an email to geb-...@googlegroups.com.

Marcin Erdmann

unread,
May 14, 2020, 1:30:22 PM5/14/20
to geb-...@googlegroups.com
On Wed, May 13, 2020 at 10:50 PM Gordon Freeman <sda.f...@gmail.com> wrote:
For 2. I found this article https://blog.jdriven.com/2018/10/combining-spock-junit-5-tests/ so, Junit5 and Spock 1.2 should work together.
I`m not familiar with categories in Junit, should I somehow mark tests to some categories before create Gradle task?

 
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/4bb8a13c-0f3a-40a6-beda-14836d672421%40googlegroups.com.

Gordon Freeman

unread,
May 14, 2020, 6:50:51 PM5/14/20
to Geb User Mailing List
Marcin, thanks a lot! I very appreciate it. 👍

Marcin Erdmann

unread,
May 15, 2020, 2:54:13 AM5/15/20
to geb-...@googlegroups.com
You're very much welcome, Gordon.

To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/df6ea5de-98fd-4818-8bd9-0b6c45815b1d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages