Gradle Test task 로깅 설정하기

gradle Nov 29, 2016

TDD의 맹신자는 아니지만 보통 개발을 진행할 때 테스트 케이스를 먼저 만들면서 코딩하느라 디버깅을 테스트 케이스로 많이 하는 편인데 Gradle test 태스크는 기본적으로 console 로깅이 disable된 채로 구동된다.

개발시에는 stacktrace를 상세하게 볼 필요도 있는데 아래 설정을 통해 볼 수 있다.

Gradle reference는 잘되어 있는 듯 잘 안되어 있는(?) 뭔가 하나씩 빠져 있는 느낌이랄까..

기본값이 어떤값으로 되어 있다던지 어떤 값이 적절하게 들어가는지 상세하게 안나와 있는 경우가 좀 있는 편인거 같다.

Test task 로깅 설정

test {
    testLogging {
        // test jvm의 standard out and standard error을 console에 출력한다.
        showStandardStreams = true
        showCauses = true
        showExceptions = true
        showStackTraces = true
        exceptionFormat = 'full'
    }
}

참고 TestLogging Property

Property Description
displayGranularity 로그로 기록되는 이벤트의 표시 단위.
"0"으로 세팅할 때 메소드 단위 이벤트는 "Test Run > Test Worker x > org.SomeClass > org.someMethod"로 표시된다.
"2"로 세팅하면 같은 이벤트는 "org.someClass > org.someMethod"로 표시된다.
events 로깅될 이벤트.
TestLogEvent (FAILED, PASSED, SKIPPED, STANDARD_ERROR, STANDARD_OUT, STARTED)
exceptionFormat showStackTrace가 true 여야만 활성화
로깅하려는 test exception 포맷
TestExceptionFormat(FULL, SHORT)
maxGranularity 로깅되는 이벤트 표시방식(max)
"0" test를 수행하는 gradle test suite 전체
"1" test가 수행되는 각 test JVM 정보
"2" 테스트 클래스
"3" 테스트 메소드.
minGranularity maxGranularity 와 동일
showCauses showException가 true여야만 활성화
테스트 수행 시 exception이 발생 했을 때 causes 정보를 보여준다.
showExceptions 테스트 수행 시 exception이 발생 했을 때 exception정보를 로깅한다. 보통 "Failed" 이벤트 발생 시 수행한다.
showStackTraces 테스트 수행 시 exception이 발생 했을 때 showStackTraces정보를 보여준다.
showStandardStreams standard out, standard error 를 로깅한다.
stackTraceFilters test stack trace 정보를 filter를 통해 정제한다.
TestStackTraceFilter를 사용

Reference

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.logging.TestLogging.html

Tags

권혁

백발까지 코딩하고 싶은 상부상조 프로그래머

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.