Configuring Logging for Device Testing in Spring Boot Project using Gradle Build

I have configured a web app in Gradle using spring boot and I run tests directly through STS, but the unit test is not responsible for custom logging, this is the same as running tests while Gradle builds. How can I configure the log so that unit tests use the logback.xml file that I added to src / test / resources when running a test separately from STS at the same time or when running tests as part of a Gradle Build?

My Gradle file looks like this

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "http://repo.spring.io/libs-release" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'

eclipse{
        classpath {
            downloadSources=true
    }
}

war {
    baseName = 'wiggle'
    version =  '0.0.1-BUILD-SNAPSHOT'
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "http://repo.spring.io/libs-release" }
}

configurations {
    providedRuntime
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-social-facebook")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("com.jolbox:bonecp:0.8.0.RELEASE")
    // Test Dependencies
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.12'
}

      

I have my own logback.xml (to keep everything in debug mode)

Anadis-MacBook-Pro:wiggle anadi$ cat src/test/resources/logback.xml 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d %5p | %t | %-55logger{55} | %m %n</pattern>
        </encoder>
    </appender>

    <logger name="org.springframework">
        <level value="DEBUG" />
    </logger>

    <root>
        <level value="DEBUG" />
        <appender-ref ref="CONSOLE" />
    </root>

      

However, when I run the test through Gradle or directly from STS. Logging doesn't work for Spring, the output I get is

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/anadi/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Applications/springsource/sts-3.5.1.RELEASE/plugins/org.springsource.ide.eclipse.gradle.toolingapi_3.5.1.201404300713-RELEASE/lib/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
2014-08-03 18:37:29,921 DEBUG | main | o.s.test.context.junit4.SpringJUnit4ClassRunner         | SpringJUnit4ClassRunner constructor called with [class wiggle.test.system.persistence.MemberPersistenceSystemTest]. 
2014-08-03 18:37:30,215 DEBUG | main | org.springframework.test.context.ContextLoaderUtils     | Found explicit ContextLoader class [org.springframework.test.context.support.AnnotationConfigContextLoader] for context configuration attributes [ContextConfigurationAttributes@15c955b7 declaringClass = 'wiggle.test.system.persistence.MemberPersistenceSystemTest', locations = '{}', classes = '{class wiggle.test.config.wiggleTestPersistenceContext}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.support.AnnotationConfigContextLoader'] 
2014-08-03 18:37:30,356 DEBUG | main | org.springframework.test.context.ContextLoaderUtils     | Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,500 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved @ProfileValueSourceConfiguration [null] for test class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,501 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,520 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved @ProfileValueSourceConfiguration [null] for test class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,520 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,539 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved @ProfileValueSourceConfiguration [null] for test class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,539 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,541 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved @ProfileValueSourceConfiguration [null] for test class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,541 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,543 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved @ProfileValueSourceConfiguration [null] for test class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,543 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,572 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved @ProfileValueSourceConfiguration [null] for test class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,573 DEBUG | main | org.springframework.test.annotation.ProfileValueUtils   | Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [wiggle.test.system.persistence.MemberPersistenceSystemTest] 
2014-08-03 18:37:30,690 DEBUG | main | o.s.t.c.support.DirtiesContextTestExecutionListener     | After test method: context [DefaultTestContext@6e200e2d testClass = MemberPersistenceSystemTest, testInstance = wiggle.test.system.persistence.MemberPersistenceSystemTest@7a82e4d6, testMethod = test@MemberPersistenceSystemTest, testException = java.lang.NullPointerException, mergedContextConfiguration = [MergedContextConfiguration@277ddc70 testClass = MemberPersistenceSystemTest, locations = '{}', classes = '{class wiggle.test.config.wiggleTestPersistenceContext}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.AnnotationConfigContextLoader', parent = [null]]], class dirties context [false], class mode [null], method dirties context [true]. 
2014-08-03 18:37:30,816 DEBUG | main | o.s.t.c.support.DirtiesContextTestExecutionListener     | After test class: context [DefaultTestContext@6e200e2d testClass = MemberPersistenceSystemTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@277ddc70 testClass = MemberPersistenceSystemTest, locations = '{}', classes = '{class wiggle.test.config.wiggleTestPersistenceContext}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.AnnotationConfigContextLoader', parent = [null]]], dirtiesContext [false].

      

+4


source to share





All Articles