print the name of the specification currently running

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

print the name of the specification currently running

Todd Bradley
I've inherited some Spock tests that I'm trying to improve, and one thing I'd like is to print a log message at the start of each specification, saying something like "Now starting specification 'check that frobozz is never true'". The creator of these tests has log.info statements (thanks to @Slf4j) at the start and end of each specification, but there's gotta be a better way, like adding log.info statements to the setup() method or some such. I just don't know how to get hold of the name of the currently-executing specification. Any suggestions?


Thanks,
Todd.

--
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 http://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: print the name of the specification currently running

Peter Niederwieser
Administrator
You mean at the start of each method or each class? And doesn’t your build tool support this already?

On 17 Sep 2014, at 20:48, Todd Bradley <[hidden email]> wrote:

I've inherited some Spock tests that I'm trying to improve, and one thing I'd like is to print a log message at the start of each specification, saying something like "Now starting specification 'check that frobozz is never true'". The creator of these tests has log.info statements (thanks to @Slf4j) at the start and end of each specification, but there's gotta be a better way, like adding log.info statements to the setup() method or some such. I just don't know how to get hold of the name of the currently-executing specification. Any suggestions?


Thanks,
Todd.

--
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 http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
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 http://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: print the name of the specification currently running

Todd Bradley
Sorry, I mean at the start of each method (not specification). We're running these tests in Eclipse most of the time. The JUnit test runner shows visually as each method is executed, but it would be nice to have it printed to the console, too. That way, when looking at the output from the test later, you can easily see what log messages came from the setup of the test and what came from the test itself.

What would be REALLY great is to print out when each of the given/when/then sections is starting. We're using Spock for system integration tests that can take several minutes to run. So having rich logging output from the test is more important than it might be for unit tests.


On Wednesday, September 17, 2014 9:51:51 PM UTC-6, Peter Niederwieser wrote:
You mean at the start of each method or each class? And doesn’t your build tool support this already?

On 17 Sep 2014, at 20:48, Todd Bradley <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="T327pmOqNwcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">tod...@...> wrote:

I've inherited some Spock tests that I'm trying to improve, and one thing I'd like is to print a log message at the start of each specification, saying something like "Now starting specification 'check that frobozz is never true'". The creator of these tests has <a href="http://log.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;">log.info statements (thanks to @Slf4j) at the start and end of each specification, but there's gotta be a better way, like adding <a href="http://log.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;">log.info statements to the setup() method or some such. I just don't know how to get hold of the name of the currently-executing specification. Any suggestions?


Thanks,
Todd.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="T327pmOqNwcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">spockframewor...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="T327pmOqNwcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">spockfr...@googlegroups.com.
Visit this group at <a href="http://groups.google.com/group/spockframework" target="_blank" onmousedown="this.href='http://groups.google.com/group/spockframework';return true;" onclick="this.href='http://groups.google.com/group/spockframework';return true;">http://groups.google.com/group/spockframework.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 http://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: print the name of the specification currently running

Peter Niederwieser
Administrator
One way to get a the current test name is to use JUnit’s `TestName` rule. The logging could then happen in the `setup` method of a base class. Another solution is to write a JUnit rule that takes care of the logging. (There might already exist one.) Another solution is to write a global Spock extension that takes care of the logging (see https://github.com/spockframework/spock/tree/groovy-1.8/spock-core/src/main/java/org/spockframework/runtime/extension). 

Logging entry of each section isn’t currently possible, but may be supported in the future.

Cheers,
Peter

On 17 Sep 2014, at 21:03, Todd Bradley <[hidden email]> wrote:

Sorry, I mean at the start of each method (not specification). We're running these tests in Eclipse most of the time. The JUnit test runner shows visually as each method is executed, but it would be nice to have it printed to the console, too. That way, when looking at the output from the test later, you can easily see what log messages came from the setup of the test and what came from the test itself.

What would be REALLY great is to print out when each of the given/when/then sections is starting. We're using Spock for system integration tests that can take several minutes to run. So having rich logging output from the test is more important than it might be for unit tests.


On Wednesday, September 17, 2014 9:51:51 PM UTC-6, Peter Niederwieser wrote:
You mean at the start of each method or each class? And doesn’t your build tool support this already?

On 17 Sep 2014, at 20:48, Todd Bradley <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="T327pmOqNwcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">tod...@...> wrote:

I've inherited some Spock tests that I'm trying to improve, and one thing I'd like is to print a log message at the start of each specification, saying something like "Now starting specification 'check that frobozz is never true'". The creator of these tests has <a href="http://log.info/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;">log.info statements (thanks to @Slf4j) at the start and end of each specification, but there's gotta be a better way, like adding <a href="http://log.info/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flog.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGiFwT-1qFB2PcvymGq972yAwReIA';return true;">log.info statements to the setup() method or some such. I just don't know how to get hold of the name of the currently-executing specification. Any suggestions?


Thanks,
Todd.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="T327pmOqNwcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">spockframewor...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="T327pmOqNwcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">spockfr...@googlegroups.com.
Visit this group at <a href="http://groups.google.com/group/spockframework" target="_blank" onmousedown="this.href='http://groups.google.com/group/spockframework';return true;" onclick="this.href='http://groups.google.com/group/spockframework';return true;">http://groups.google.com/group/spockframework.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.


--
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 http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
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 http://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: print the name of the specification currently running

Todd Bradley-2
Thanks, Peter. I went with the first suggestion, which was quite easy to implement.

On Wed, Sep 17, 2014 at 10:29 PM, [hidden email] <[hidden email]> wrote:
One way to get a the current test name is to use JUnit’s `TestName` rule. The logging could then happen in the `setup` method of a base class. Another solution is to write a JUnit rule that takes care of the logging. (There might already exist one.) Another solution is to write a global Spock extension that takes care of the logging (see https://github.com/spockframework/spock/tree/groovy-1.8/spock-core/src/main/java/org/spockframework/runtime/extension). 

Logging entry of each section isn’t currently possible, but may be supported in the future.

Cheers,
Peter


On 17 Sep 2014, at 21:03, Todd Bradley <[hidden email]> wrote:

Sorry, I mean at the start of each method (not specification). We're running these tests in Eclipse most of the time. The JUnit test runner shows visually as each method is executed, but it would be nice to have it printed to the console, too. That way, when looking at the output from the test later, you can easily see what log messages came from the setup of the test and what came from the test itself.

What would be REALLY great is to print out when each of the given/when/then sections is starting. We're using Spock for system integration tests that can take several minutes to run. So having rich logging output from the test is more important than it might be for unit tests.


On Wednesday, September 17, 2014 9:51:51 PM UTC-6, Peter Niederwieser wrote:
You mean at the start of each method or each class? And doesn’t your build tool support this already?

On 17 Sep 2014, at 20:48, Todd Bradley <[hidden email]> wrote:

I've inherited some Spock tests that I'm trying to improve, and one thing I'd like is to print a log message at the start of each specification, saying something like "Now starting specification 'check that frobozz is never true'". The creator of these tests has log.info statements (thanks to @Slf4j) at the start and end of each specification, but there's gotta be a better way, like adding log.info statements to the setup() method or some such. I just don't know how to get hold of the name of the currently-executing specification. Any suggestions?


Thanks,
Todd.

--
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 spockframewor...@googlegroups.com.
To post to this group, send email to spockfr...@googlegroups.com.
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.


--
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 http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
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 http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
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 http://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: print the name of the specification currently running

kriegaex
This post has NOT been accepted by the mailing list yet.
In reply to this post by Peter Niederwieser
Hi Peter.

Sorry for digging up this old thread, but I did what should usually be done before asking new questions: search the archive.

As you can see at https://github.com/arquillian/arquillian-testrunner-spock/issues/24, I added my own custom JUnit rule, burt have some Arquillian problems on some (not all) platforms. Anyway, this is not the question, just the basic info. The real question is:

How would I go about writing a Spock extension? I see the source code in the repo, but the Spock user manual just shows a "to do" for where there should be a how-to. Can you help me with a concrete example? Maybe extending Spock creates less problems with Arquillian than using a JUnit rule. I want to give it a try.

Regards
Alexander
Loading...