How to log to console with Groovy using JUnit?

112 views
Skip to first unread message

Mick Knutson

unread,
Apr 5, 2012, 7:26:39 PM4/5/12
to cu...@googlegroups.com
I have tried:

World {
    System.out.println "@@@@@@@@@@@@@@@@@@@@@@@@@@@"
    println "^^^^^^^^^^^^^^^^^^^^^^^^"
    logger.info "XXXXXXXXXXXXXXXXXXX"

    new CustomWorld()
}


but I cannot seem to get anything to print to console while running junit.
I am using LOGBACK and want to see some of the data in my steps.

---
Thank You…

Mick Knutson, President

BASE Logic, Inc. & BLiNC Magazine
Enterprise Solutions Architecture and Extreme Athlete

p. (855) BASE-LOGIC: (227-3564-42)
p. (478) BASE-LOGIC (227-3564-42)
f. (855) BASE-LOGIC: (227-3564-42)

Mick Knutson

unread,
Apr 5, 2012, 9:03:56 PM4/5/12
to cu...@googlegroups.com
Strange thing is I added a pom.xml to run Maven and get this output:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running calc.RunCukesTest
# language: en
Feature: Division
  In order to avoid silly mistakes
  Cashiers must be able to calculate a fraction

  @important
  Scenario: Regular numbers                    ←[90m# calc\division.feature:7←[0m
    ←[90mGiven ←[0m←[90mI have entered ←[0m←[90m←[1m3←[0m←[90m into ←[0m←[90m←[1mthe←[0m←[90m calculator←[0m ←[90m# CalculatorStep
s.groovy:31←[0m
←[1A    ←[32mGiven ←[0m←[32mI have entered ←[0m←[32m←[1m3←[0m←[32m into ←[0m←[32m←[1mthe←[0m←[32m calculator←[0m ←[90m# Calculator
Steps.groovy:31←[0m
    ←[90mAnd ←[0m←[90mI have entered ←[0m←[90m←[1m2←[0m←[90m into ←[0m←[90m←[1mthe←[0m←[90m calculator←[0m   ←[90m# CalculatorStep
s.groovy:31←[0m
←[1A    ←[32mAnd ←[0m←[32mI have entered ←[0m←[32m←[1m2←[0m←[32m into ←[0m←[32m←[1mthe←[0m←[32m calculator←[0m   ←[90m# Calculator
Steps.groovy:31←[0m
    ←[90mWhen ←[0m←[90mI press ←[0m←[90m←[1mdivide←[0m                        ←[90m# CalculatorSteps.groovy:39←[0m
←[1A    ←[32mWhen ←[0m←[32mI press ←[0m←[32m←[1mdivide←[0m                        ←[90m# CalculatorSteps.groovy:39←[0m
    ←[90mThen ←[0m←[90mthe stored result should be ←[0m←[90m←[1m1.9←[0m       ←[90m# CalculatorSteps.groovy:43←[0m
←[1A    ←[31mThen ←[0m←[31mthe stored result should be ←[0m←[31m←[1m1.9←[0m       ←[90m# CalculatorSteps.groovy:43←[0m
      ←[31morg.codehaus.groovy.runtime.InvokerInvocationException: Assertion failed:

      assert expected == result
             |        |  |
             1.9      |  1.5
                      false

But running the same thing with Gradle gives me this:

21:02:27.648 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':test'
21:02:27.654 [DEBUG] [org.gradle.execution.DefaultTaskGraphExecuter] Timing: Executing the DAG took 20.908 secs
21:02:27.660 [LIFECYCLE] [org.gradle.BuildResultLogger]
21:02:27.665 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD SUCCESSFUL
21:02:27.670 [LIFECYCLE] [org.gradle.BuildResultLogger]
21:02:27.674 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 24.415 secs


What am I missing here?
Is there something to do with the junit runner? Maybe the groovy execution?

Cause all my decencies are the same.



---
Thank You…

Mick Knutson, President, Certified Spring Instructor

BASE Logic, Inc.
Enterprise Architecture, Design, Training & Agile Consulting
p. (855) BASE-LOGIC: (227-3564-42)
gv. (478) BASE-LOGIC (227-3564-42)
f. (855) BASE-LOGIC: (227-3564-42)

David Kowis

unread,
Apr 6, 2012, 8:18:16 AM4/6/12
to cu...@googlegroups.com
On 04/05/2012 08:03 PM, Mick Knutson wrote:
>
> What am I missing here?
> Is there something to do with the junit runner? Maybe the groovy execution?

Nope. it's a gradle issue. If you want to have the output shown in the
console, you can do:

test.testLogging.showStandardStreams = true


That should get it closer to what you expect,
David

Mick Knutson

unread,
Apr 6, 2012, 9:24:31 AM4/6/12
to cu...@googlegroups.com
That is what I needed thanks!
Never would have guessed on that one. Much appreciated

---
Thank You…

Mick Knutson, President, Certified Spring Instructor

BASE Logic, Inc.
Enterprise Architecture, Design, Training & Agile Consulting
p. (855) BASE-LOGIC: (227-3564-42)
gv. (478) BASE-LOGIC (227-3564-42)
f. (855) BASE-LOGIC: (227-3564-42)
---



Reply all
Reply to author
Forward
0 new messages