n00b Spock & Logging Question

2,083 views
Skip to first unread message

StefK

unread,
Dec 9, 2011, 2:45:12 PM12/9/11
to spockfr...@googlegroups.com
Hi, 

Summary: I am using spock for testing and my method takes in a logger (org.slf4j.Logger) and I would like to capture the logging output sent to that logger during test execution.

Problem: I don't know how to do this :(

Details:
e.g.  the method I am testing:

public Map myTestMethod(Logger log,  ... )
{
  ... 
  log.info(" This is a log I would like to capture with the test output")
  ...

& in my spock test:
class Tester extends Specification {

  Logger logger = LoggerFactory.getLogger(Tester.class);
  
  def setup(){
     ...
  }

  def "Test method"()
  {
     setup: 'Some setup stuff'
     TestObject tObj = new ...

     when: ' test the method invocation'
     Map x = tObj.myTestMethod(logger,  ...)

     then: ' compare the results'
     x.size() == 3
  }  
}

So I would like to capture the "This is a log I would like to capture with the test output" in the output of the test reporting. But what I do analogously above isn't working for me. Is there some test framework file I missed? or?

Peter Niederwieser

unread,
Dec 9, 2011, 3:08:41 PM12/9/11
to spockfr...@googlegroups.com
The question isn't specific to Spock. You need to configure your logging framework (SLF4J is just the API) and/or environment (e.g. build tool) to log to standard out. For example, if you use Log4J you would put a log4j.properties on the class path.

Cheers,
Peter

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spockframework/-/_7Wn0w2BwdIJ.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.

StefK

unread,
Dec 9, 2011, 4:04:48 PM12/9/11
to spockfr...@googlegroups.com
Confirmed, I'm a n00b. 

Thanks :) 


StefK

unread,
Dec 9, 2011, 4:38:48 PM12/9/11
to spockfr...@googlegroups.com
and just to confirm, Spock has no intention of having some built in Logger that we can pass round and set?

Hans Westerbeek

unread,
Dec 9, 2011, 10:22:10 PM12/9/11
to spockfr...@googlegroups.com
What you're looking for is built-into Groovy 1.8.x:

http://docs.codehaus.org/display/GROOVY/Groovy+1.8+release+notes#Groovy1.8releasenotes-@Log

@Slf4J would do the trick in your case..

On Fri, Dec 9, 2011 at 10:38 PM, StefK <stefan....@gmail.com> wrote:
> and just to confirm, Spock has no intention of having some built in Logger
> that we can pass round and set?
>

> --
> You received this message because you are subscribed to the Google Groups
> "Spock Framework - User" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/spockframework/-/r8FAFNboKcsJ.

StefK

unread,
Dec 12, 2011, 6:19:40 PM12/12/11
to spockfr...@googlegroups.com
oh awesome, thanks
Reply all
Reply to author
Forward
0 new messages