Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Multiple When..Then using single feature SPOCK-Groovy

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi

I'm developing automation test suit using Geb,Spock and groovy. Verifying multiple when..then block in single feature any one block got failed, It stop execution. What are the logic we have to put for running all the blocks even any when..then block failed. Please guide me.

Thanks
-Moorthy
 
Rajesh Moo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajesh Moo wrote:
Hi

I'm developing automation test suit using Geb,Spock and groovy. Verifying multiple when..then block in single feature any one block got failed, It stop execution. What are the logic we have to put for running all the blocks even any when..then block failed. Please guide me.

Thanks
-Moorthy



For example
def "test"(){
       given:
       println(" checking 3 nos")
       when:
       def a = 5
       def b = 10
       def c = 20

       if (a < b)
           println("Pass")

       then:
       true

       when:

       def a1 = 5
       def a2 = 10
       def a3 = 20
       if (a2 > a3)
           println("Fail")

       then:
       false
       
       when:
       def a11 = 5
       def a22 = 10
       def a33 = 20
       if (a33 > a11)
           println("pass")

       then:
       true

It never moves to 3rd block.It throws error and execution stops
 
Marshal
Posts: 16631
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. This is an example of how NOT to write tests - go back and read the primer again: http://www.groovy-lang.org/style-guide.html (Edit: wrong URL) Correct URL to Spock Primer: http://spockframework.org/spock/docs/1.0/spock_primer.html

2. Of course it will error out. Your second block will always fail because its then clause evaluates to false. To pass, expressions in the then clause must evaluate to true. Again, a hard-coded false value in the then clause will cause the test to always fail.

When posting code, please Use Code Tags
 
Junilu Lacar
Marshal
Posts: 16631
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Note that this code doesn't do what I think you believe it does. The then on line 4 is not the "then" part of the if statement on line 1. Rather, it is a label that marks the then-block of the feature method.

Again, you should go back and review the Spock Primer: http://spockframework.org/spock/docs/1.0/spock_primer.html and make sure you fully understand the structure of a feature method.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic