Tag Geb classes/tests for exclusion

432 views
Skip to first unread message

tapl...@gmail.com

unread,
Mar 18, 2015, 5:47:50 PM3/18/15
to geb-...@googlegroups.com

Originally Posted: http://stackoverflow.com/questions/29127169/tag-geb-classes-tests-for-exclusion

I am trying to create a simple way for excluding Geb tests from running based off of not having an optional "tag".

In my grails project I have created a "test/functional" directory for my geb files to reside. Inside this directory I have the GebConfig.groovy and SpockConfig.groovy files. I am aware that SpockConfig.groovy currently has an issue with being able to resolve classes in the project and only recognises classes provided in the BuildConfig dependencies. As such, I have created and jar'ed an annotation class "Tags" and included it in the dependencies. I can now use this annotation on my Geb tests in the following manner:

@Tags("regression")
@Tags(["smoke", "regression"])
@Tags(["in-progress", "whatever-makes-sense"])


What I would like to have now is for the SpockConfig to find all the classes in the "test/functional" directory with the @Tags annotation, and for each one that does not have System.getenv("functional.tag") in the tags array, to add the class to the runner.exclude base classes collection so it will not execute.

I am fairly new to Annotations and the processing thereof, and so far have not found an easy way to perform the lookup logic of this process. Are there existing constructs that facilitate such a process, or what logic could be implimented to fulfill this task?

J. David Beutel

unread,
Mar 18, 2015, 6:57:30 PM3/18/15
to geb-...@googlegroups.com
This question is more about Spock than Geb, but anyway, I've done something like what you are trying to do, and had to implement Spock's IGlobalExtension.

To skip specs that have an annotation, you could make an extension implementing Spock's IAnnotationDrivenExtension.  See IgnoreExtension and IgnoreIfExtension for examples.

However, if you want to skip specs that *don't* have an annotation, you will need to implement IGlobalExtension.  See IncludeExcludeExtension for an example.  You can publish it as a service in your jar, with Grails, for example, using a script like the one below.

Cheers,
11011011

includeTargets << grailsScript('Init')
includeTargets << grailsScript('Compile')

target(buildAll: 'build the taps-spock-extensions.jar') {
    depends(compile, buildJar)
}

target(buildJar: 'build the taps-spock-extensions.jar') {
    def libDir = new File((File)grailsSettings.baseDir, 'lib')
    def jarFile = new File(libDir, 'taps-spock-extensions.jar')

    def serviceType = 'org.spockframework.runtime.extension.IGlobalExtension'
    ant.delete(quiet: true, file: jarFile)
    ant.jar( destfile: jarFile ) {
        fileset(dir: classesDirPath) {
            include(name: '**/*ExecuteWhenPropertySet*.class')  // 3 top classes + a couple closures
            include(name: '**/ReportConnectionLeaksExtension*.class')  // top class & nested Listener
        }
        // Generate the serviceType file in META-INF/services, to plugin to Spock's ExtensionClassesLoader.
        service(type: serviceType) {
            provider(classname: 'edu.hawaii.its.taps.testing.OnlyExecuteWhenPropertySetExtension')
            provider(classname: 'edu.hawaii.its.taps.testing.ReportConnectionLeaksExtension')
        }
    }
}


setDefaultTarget( buildAll )
--
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 post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/399543de-5b08-4564-8ba7-8e58ce53fc4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bob Brown

unread,
Mar 18, 2015, 7:20:14 PM3/18/15
to geb-...@googlegroups.com

J. David Beutel

unread,
Mar 18, 2015, 7:53:07 PM3/18/15
to geb-...@googlegroups.com
That's a good alternative, including its links to this background:

http://blog.proxerd.pl/article/segregating-spock-specifications-with-spockconfig-groovy-and-annotations

If the OP is willing to use multiple annotations, instead of
parameterizing a single annotation, then he may not need to create his
own extension.

Cheers,
11011011

tapl...@gmail.com

unread,
Mar 18, 2015, 10:19:04 PM3/18/15
to geb-...@googlegroups.com, li...@getsu.com
@Bob Brown & @J. David Beutel
I google crawled both those resources while trying to find a solution.  At one point I did create and jar three annotations; @Smoke, @Regression, @InProgress.  The issue with this is the code base does not really have a static set of tags.

The situation I am in is that we currently use a functional testing suite (ThoughtWorks' Twist) which allows for our QAs to easily tag integration tests and be able to run a subset of tests by the tags.  They use any number of tags ranging from smoke, regression, inprogress, wip (work in progress), dates, story card numbers from our card wall for reference, etc.  Additionally, not all the groups in the shop are required to use the same tags for the most part the QA team is not what you would call "java/groovy" proficient.

Given the preceding, having an alternative suite that allows similar functionality in as easy a manner as possible, I feel, greatly increases the chances of the QAs adopting the alternative suite.


@J. David Beutel
Much appreciation for pointing out the IgnoreIfExtension.  Once pointed in this direction I was able follow the styling of IgnoreIfExtension and IgnoreIf and create classes "IgnoreUnlessExtension" and "IgnoreUnless" which take in an array of strings and checks if the "functional.tag" environment variable is in preset, and if not performs the skip option so the tests are ignored, which is what I was after!  :D  Don't think I need the custom SpockConfig.groovy file now.

I'll document this on stack overflow tomorrow and give you credit.  Again, must appreciated.  And thanks all for the replies.

dw...@groupon.com

unread,
Dec 5, 2017, 9:10:02 AM12/5/17
to Geb User Mailing List
@J. David Beutel

I am new to Geb Spock with maven. I want to tag my tests for regression, smoke etc, in a simple manner like in TestNG. If you could explain how I could use IgnoreIfExtension in my case will be helpful.

Thanks!!

J. David Beutel

unread,
Dec 6, 2017, 3:29:12 AM12/6/17
to geb-...@googlegroups.com
This is more of a Spock question.  I can't compare with TestNG or Maven, but here's a good example of using @IgnoreIf:

http://mrhaki.blogspot.com/2014/06/spocklight-ignore-specifications-based.html

Here's OP's question and answer:

https://stackoverflow.com/questions/29127169/tag-geb-classes-tests-for-exclusion

There are various ways you could do it.  The best approach depends on how you want to run your tests.  I used an IGlobalExtension to exclude specs that were not annotated, because I had problems with the classpath in Spock config files on Grails 1 & 2.

Instead of that, if you can run it with a "spock.configuration" system property, and your build system supports the config classpath properly, then you could use multiple Spock config files (regression, smoke, etc) with include and exclude by corresponding annotations or marker interfaces:

http://spockframework.org/spock/docs/1.1/all_in_one.html#_spock_configuration_file
http://spockframework.org/spock/docs/1.1/all_in_one.html#_include_and_exclude
http://mrhaki.blogspot.com/2015/08/spocklight-including-or-excluding.html
http://mrhaki.blogspot.com/2015/08/spocklight-include-or-exclude.html

By the way, for regression tests, Spock already has an annotation, @Issue, that may be useful:

http://spockframework.org/spock/docs/1.1/all_in_one.html#_issue

Cheers,
11011011
--
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 post to this group, send email to geb-...@googlegroups.com.

Dwiparna Pal

unread,
Dec 6, 2017, 11:21:11 AM12/6/17
to geb-...@googlegroups.com
@David, Thanks for the reply. I'll try this out.

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

To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/0c40445b-ae71-4e6d-8589-b2e009849e58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Geb User Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/geb-user/MHrMWvFa8EQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to geb-user+unsubscribe@googlegroups.com.

To post to this group, send email to geb-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages