Logging block labels in real-time

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Logging block labels in real-time

Brian Stewart
Hi, all! Is it possible to turn on real-time logging (not post-run reports) that display the block labels? Here is an example of what I'm trying to do:

def 'test block-level logging'() {
    given
: 'some setup'
   
def x = 5
   
   
when: 'action is taken'
    x
++

   
then: 'result matches expected'
    x
== 6
}

I would like this spec to produce logging output something like this (with or without the "given"/"when"/"then"):
given: some setup
when: action is taken
then: result matches expected

I looked at some extensions, but only saw hooks for before-spec and before-feature, not before-block.

Any pointers would be appreciated!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging block labels in real-time

David Lumpkin
I've looked for this too but never found a good way to do it

On Friday, May 20, 2016 at 1:55:56 PM UTC-6, Brian Stewart wrote:
Hi, all! Is it possible to turn on real-time logging (not post-run reports) that display the block labels? Here is an example of what I'm trying to do:

def 'test block-level logging'() {
    given
: 'some setup'
   
def x = 5
   
   
when: 'action is taken'
    x
++

   
then: 'result matches expected'
    x
== 6
}

I would like this spec to produce logging output something like this (with or without the "given"/"when"/"then"):
given: some setup
when: action is taken
then: result matches expected

I looked at some extensions, but only saw hooks for before-spec and before-feature, not before-block.

Any pointers would be appreciated!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging block labels in real-time

Raghu Kiran
In reply to this post by Brian Stewart
BDD test case writing is cool, This shoud reflect in reporting too. 

AbstractRunListener does not have beforeBlock and afterBlock contracts in Interface... 

Is there a way we can raise an enhancement request for this to be included to spock? Logging is where the teams and folks look at after automation runs and having good log that says what failed at which Block certainly helps. 


On Saturday, 21 May 2016 01:25:56 UTC+5:30, Brian Stewart wrote:
Hi, all! Is it possible to turn on real-time logging (not post-run reports) that display the block labels? Here is an example of what I'm trying to do:

def 'test block-level logging'() {
    given
: 'some setup'
   
def x = 5
   
   
when: 'action is taken'
    x
++

   
then: 'result matches expected'
    x
== 6
}

I would like this spec to produce logging output something like this (with or without the "given"/"when"/"then"):
given: some setup
when: action is taken
then: result matches expected

I looked at some extensions, but only saw hooks for before-spec and before-feature, not before-block.

Any pointers would be appreciated!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging block labels in real-time

Brian Stewart
I just stumbled across a simple way to do this, and thought I'd update here. Just add the logging statement where the block description would be. A wrapper function around `log.info()` would make it even cleaner. 

def 'test block-level logging'() {
    given
: log.info 'some setup'
    
def x = 5
    ...

}

Brian

On Thursday, September 15, 2016 at 10:38:12 AM UTC-5, Raghu Kiran wrote:
BDD test case writing is cool, This shoud reflect in reporting too. 

AbstractRunListener does not have beforeBlock and afterBlock contracts in Interface... 

Is there a way we can raise an enhancement request for this to be included to spock? Logging is where the teams and folks look at after automation runs and having good log that says what failed at which Block certainly helps. 


On Saturday, 21 May 2016 01:25:56 UTC+5:30, Brian Stewart wrote:
Hi, all! Is it possible to turn on real-time logging (not post-run reports) that display the block labels? Here is an example of what I'm trying to do:

def 'test block-level logging'() {
    given
: 'some setup'
   
def x = 5
   
   
when: 'action is taken'
    x
++

   
then: 'result matches expected'
    x
== 6
}

I would like this spec to produce logging output something like this (with or without the "given"/"when"/"then"):
given: some setup
when: action is taken
then: result matches expected

I looked at some extensions, but only saw hooks for before-spec and before-feature, not before-block.

Any pointers would be appreciated!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging block labels in real-time

Robert Evans
In reply to this post by Brian Stewart


On Friday, 20 May 2016 20:55:56 UTC+1, Brian Stewart wrote:
Hi, all! Is it possible to turn on real-time logging (not post-run reports) that display the block labels? Here is an example of what I'm trying to do:

def 'test block-level logging'() {
    given
: 'some setup'
   
def x = 5
   
   
when: 'action is taken'
    x
++

   
then: 'result matches expected'
    x
== 6
}

I would like this spec to produce logging output something like this (with or without the "given"/"when"/"then"):
given: some setup
when: action is taken
then: result matches expected

I looked at some extensions, but only saw hooks for before-spec and before-feature, not before-block.

Any pointers would be appreciated!


You can make the method name a more dynamic which turns the problem on its head a little but ultimately gives you what you want which is presumably to see the values of your variables and make your programs easier to debug.

def "when I add #addValue to x=#x the result is #expected"() {
   
when:
   
def result = x + addValue

   
then: // (possibly expect: I cannot remember.)
   
assert result == expected

   
where:
   
| x | addValue | expected  |
   
| 5 | 1        | 6         |
}


For more than 1 row in the where: portion use the @Unroll annotation above the method name to let spock know to treat each row of input as a single independent test - otherwise it'll assume your assertions are all a part of a single larger test and you won't get the right output.

HTH 
Rob

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...