Lee, Stefan is definitely right that this question is not really a Geb question as Geb is test and build framework agnostic (although I'm sure a lot people will agree that using it with Spock is the idiomatic way) and running particular tests is a concern for the test and build framework in my opinion.
On the other hand, I don't think Stefan is right when saying that you need both includes and excludes for categories on a gradle test task as I use JUnit categories extensively with Spock and Gradle myself and only ever specify either includes or excludes. Your setup looks right to me, but can you please try to remove @RunWith(JUnit4) annotation from the class (by default it is not necessary to run JUnit4 tests with Gradle) and move your category annotation onto the class (I know that it should also work on methods but I know for sure that categories work when they are located on classes so I'm trying to remove as many variables as possible). I don't know if it has anything to do with you seeing unexpected results, but can you please change the package name to be lowercase? By convention, package names start with a lower case in jvm languages. Finally, what exactly do you mean when you say that you have not been successful? Do you see no tests executed, all tests executed or some error when running your custom useCategory test task? Cheers, Marcin On Fri, Jun 30, 2017 at 9:27 PM, Lee <[email protected]> wrote: > Thanks Stefan. > > We may have lots of Categories though. It would be preferable to just > 'include' what I'd like to run and then just ignore everything else without > having to implicitly define the 'exclude' line (especially if we have tests > that aren't annotated yet). > > Alternatively, I was hoping that there may just be something built into > Geb to handle this. I've previously used C#, Selenium and MSBuild where we > could pass in 'categories' as parameters via the command line and only > those tests would be executed. Everything else was ignored. I got spoiled > to that and was hoping there was someway to do something similar with Geb > and Gradle. ;-) > > On Friday, June 30, 2017 at 3:08:07 PM UTC-5, Stefan Hildebrandt wrote: >> >> Hi, >> >> it's not a geb question. You are use plain junit in your example. It's a >> gradle configuration. >> >> Along to https://docs.gradle.org/3.3/userguide/java_plugin.html#t >> est_grouping or your Example (https://github.com/junit-team >> /junit4/wiki/Categories) you are missing the >> >> excludeCategories >> >> to disable some tests. >> >> Best Regards >> >> Stefan >> >> ------------------------------ >> >> *Von: *"Lee" <[email protected]> >> *An: *"Geb User Mailing List" <[email protected]> >> >> *Gesendet: *Freitag, 30. Juni 2017 21:55:51 >> *Betreff: *[geb-user] Is there something like 'Categories' within Geb? >> >> I'm new to Geb and would like to be able utilize something like >> Categories in JUnit to annotate tests, and then be able to execute only >> tests with certain categories/annotations. >> >> I've tried annotating some tests and then executing a Gradle task, as >> noted at https://github.com/junit-team/junit4/wiki/Categories, but have >> not been successful. >> >> Is there another way to do this in Geb? Or, does anyone have any >> suggestions on how I could use JUnit Categories. >> >> Example Test I tried: >> >> package GebishOrgTest >> >> import geb.junit4.GebReportingTest >> import org.junit.Test >> import org.junit.runner.RunWith >> import org.junit.experimental.categories.Category >> import org.junit.runners.JUnit4 >> >> interface FastTest { /* category marker */ } >> >> @RunWith(JUnit4) >> class GebishOrgTest extends GebReportingTest { >> >> @Category (FastTest) >> @Test >> void canGetToTheCurrentBookOfGeb() { >> to GebishOrgHomePage >> >> manualsMenu.open() >> >> //first link is for the current manual >> assert manualsMenu.links[0].text().startsWith("current") >> >> manualsMenu.links[0].click() >> >> at TheBookOfGebPage >> } >> >> } >> >> >> Example Gradle Task: >> >> task useCategory(type: Test) { >> >> useJUnit { >> >> includeCategories 'GebishOrgTest.FastTest' >> >> } >> >> } >> >> >> >> >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/geb-user/beef3ac1-e1ea-4a7b-a104-0c0dc19e2f54%40googlegroups.com >> <https://groups.google.com/d/msgid/geb-user/beef3ac1-e1ea-4a7b-a104-0c0dc19e2f54%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/geb-user/30f2643b-189d-41c1-b2f3-4cb1f0bb6cb7%40googlegroups.com > <https://groups.google.com/d/msgid/geb-user/30f2643b-189d-41c1-b2f3-4cb1f0bb6cb7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/CA%2B52dQRjLESNkeRnsdYaG2b%2BNRvWy%2B%3DCUwyJVnR1a7w3nfO07A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
