Spring Boot ユニットテストは、logging.level を無視します。質問する

Spring Boot ユニットテストは、logging.level を無視します。質問する

私の Maven モジュールの 1 つは、テストの実行時にログ レベルを無視します。

src/test/resources私は持っていますapplication.properties

app.name=bbsng-import-backend
app.description=Import Backend Module for Application
spring.profiles.active=test

# LOGGING
logging.level.root=error
logging.level.org.springframework.core =fatal
logging.level.org.springframework.beans=fatal
logging.level.org.springframework.context=fatal
logging.level.org.springframework.transaction=error
logging.level.org.springframework.test=error
logging.level.org.springframework.web=error
logging.level.org.hibernate=ERROR

私も試してみましたapplication-test.properties

私のアプリケーションは、特にコンテキストをロードするときに、大量のログを記録します。 を試しましたがlogback.xml、何も役に立ちません。logback-test.xmllogback-spring.xml

私のポンポン:

<parent>
    <groupId>at.company.bbsng</groupId>
    <artifactId>bbsng-import</artifactId>
    <version>0.1.0-SNAPSHOT</version>
</parent>

<artifactId>bbsng-import-backend</artifactId>
<name>bbsng-import-backend</name>

<properties>
    <start-class>at.company.bbsng.dataimport.ApplicationImportBackend</start-class>
</properties>


<dependencies>

    <!-- APPLICATION ... -->
    <dependency>
        <groupId>at.company.bbsng</groupId>
        <artifactId>bbsng-app-domain</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- SPRING ... -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- JAVAX ... -->
       ...

    <!-- COMMONS ... -->
       ...

    <!-- LOMBOK ... -->
       ...

    <!-- DB -->
       ...

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${org.springframework.boot-version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

1 つのシンプルな Test クラス:

@ContextConfiguration(classes = { ApplicationImportBackend.class })
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles({ "test" })
public class BatchJobConfigurationTests {

    @Autowired
    private JobLauncher jobLauncher;

    @Test
    public void testSimpleProperties() throws Exception {
        assertNotNull(jobLauncher);
    }

}

アプリケーション ログは DEBUG モードです。

はい、application.propertiesロードされます。間違った設定でアプリケーションを壊そうとしたことがあります。

ヒントがあればよろしくお願いします。

ベストアンサー1

さて、私が今やったことは、すべてのモジュールで次のように構成しました。

src/main/リソース:
質問に記載されているapplication.properiesようなログ記録構成を使用します。logging.level.*

src/テスト/リソース:
私はlogback-test.xml次のように使います:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <logger name="*.myapp" level="error" />
    <logger name="org.springframework.core " level="error" />
    <logger name="org.springframework.beans" level="error" />
    <logger name="org.springframework.context" level="error" />
    <logger name="org.springframework.transaction" level="error" />
    <logger name="org.springframework.web" level="error" />
    <logger name="org.springframework.test" level="error" />
    <logger name="org.hibernate" level="error" />
</configuration>

しかし、いくつかのモジュールでは application.properties を使用できるのに、別のモジュールでは無視される理由がまだわかりません...しかし、今のところは現状のままで動作しています。

しかし、背景知識を伴ういくつかのヒントは、依然として歓迎されるかもしれません。

私の回答は解決策としてマークしていません。まだ回避策のように感じられるからです。

おすすめ記事