GebSpec Classes Sequence

80 views
Skip to first unread message

romz.a...@gmail.com

unread,
Nov 9, 2016, 3:05:26 AM11/9/16
to Geb User Mailing List
H Geb User


I would like to ask if we can modify the sequence of test execution between test classes, i just observed that it was executed alphabetically


 i.e
when i run the test.
order is
1. AGebSpec.groovy, ->  2. BGebSpec.groovy. ->  3. CGebSpec.groovy.

Thanks and regards,
Romz

Marcin Erdmann

unread,
Nov 11, 2016, 4:25:26 AM11/11/16
to Geb User Mailing List
Hi Romz,

To be honest it's more a Spock question than a Geb question. You could in theory create a JUnit test suite of specifications(https://groups.google.com/forum/#!topic/spockframework/u4iwcAP8kng) which would influence the order of test class execution but I would strongly advise not to do it. 

Ideally you want your tests to be completely independent so that you can run them in any order or even more importantly on it's own. This will save you a lot of time and head scratching when a test fails because a new test has been added which runs before and modifies the state on which your tests depends - this is sometimes referred to as test bleed. Also consider a situation where you have a fixed order of all of your tests and a test which is last in that order fails - you will need to run the whole suite every single time you want to run that test otherwise you have no guarantee that it will run with the expected state.

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+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/e9305e57-ff0b-4684-8b82-033913ed4fea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Sherman

unread,
Jan 26, 2017, 10:44:58 AM1/26/17
to Geb User Mailing List
Marcin,

Thanks for that description, it makes perfect sense why you would want to do this but I'm not sure it can always be done.  For instance you wish to add, edit and delete the same thing in an application.  Or, you are adding something (say, a bookmark) and you need to test that clicking it takes you to the desired page (you can't click on any bookmark because you need to know where it is going)?  What is your suggestion for these cases?


On Friday, November 11, 2016 at 3:25:26 AM UTC-6, Marcin Erdmann wrote:
Hi Romz,

To be honest it's more a Spock question than a Geb question. You could in theory create a JUnit test suite of specifications(https://groups.google.com/forum/#!topic/spockframework/u4iwcAP8kng) which would influence the order of test class execution but I would strongly advise not to do it. 

Ideally you want your tests to be completely independent so that you can run them in any order or even more importantly on it's own. This will save you a lot of time and head scratching when a test fails because a new test has been added which runs before and modifies the state on which your tests depends - this is sometimes referred to as test bleed. Also consider a situation where you have a fixed order of all of your tests and a test which is last in that order fails - you will need to run the whole suite every single time you want to run that test otherwise you have no guarantee that it will run with the expected state.

Marcin 
On Wed, Nov 9, 2016 at 8:05 AM, <romz.a...@gmail.com> wrote:
H Geb User


I would like to ask if we can modify the sequence of test execution between test classes, i just observed that it was executed alphabetically


 i.e
when i run the test.
order is
1. AGebSpec.groovy, ->  2. BGebSpec.groovy. ->  3. CGebSpec.groovy.

Thanks and regards,
Romz

--
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.

Brian Kotek

unread,
Jan 26, 2017, 1:18:05 PM1/26/17
to Geb User Mailing List
Again, keep in mind that the order that things execute has nothing to do with Geb and everything to do with the underlying test framework you're using.

That said, Spock does have the @Stepwise annotation (http://spockframework.org/spock/javadoc/1.0/spock/lang/Stepwise.html) which forces the methods in a spec class to run in the order they're defined.

The Spec classes themselves need to be standalone, since I don't think any of the test frameworks offer a way to specify the order in which the test classes themselves execute in. If you have the need for common logic to reuse across specs, consider a helper class or a superclass that can be reused to perform the common actions (e.g. adding something before you test deleting it or clicking on it).
 

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.

Marcin Erdmann

unread,
Jan 29, 2017, 5:43:01 PM1/29/17
to Geb User Mailing List
Adam,

When I wish to add, edit and delete an item I would either:
- do it all in a single test
- split it into 3 tests and would write code that allows me to setup the application before each of them and check the state of the application after each of them in a way completely independent of the UI - for example by going directly to the DB or using something like Groovy Remote Control (https://github.com/alkemist/remote-control, unfortunately undocumented)

I would never split it into three tests and setup them to run in a particular order.

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.
Reply all
Reply to author
Forward
0 new messages