Một trong những mô-đun maven của tôi bỏ qua các cấp độ ghi nhật ký của tôi khi chạy thử nghiệm.
Trong src/test/resourcestôi có 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
Tôi cũng đã thử application-test.properties.
Ứng dụng của tôi ghi rất nhiều nhật ký, đặc biệt là khi tải ngữ cảnh. Tôi đã thử logback.xml, logback-test.xmlvà logback-spring.xmlkhông có gì giúp ích.
Pom của tôi:
<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>
Một lớp Kiểm tra đơn giản:
@ContextConfiguration(classes = { ApplicationImportBackend.class })
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles({ "test" })
public class BatchJobConfigurationTests {
@Autowired
private JobLauncher jobLauncher;
@Test
public void testSimpleProperties() throws Exception {
assertNotNull(jobLauncher);
}
}
Nhật ký ứng dụng đang ở Chế độ GỠ LỖI.
Và có, application.propertiessẽ được tải. Tôi đã cố gắng phá vỡ ứng dụng do cấu hình sai.
Cảm ơn bạn cho bất kỳ gợi ý.
application.propertiesđang được phân tích cú pháp muộn hơn so với lần khởi chạy thử nghiệm. Đó là lý do tại saoorg.springframework.testkhông ảnh hưởng đến việc ghi nhật ký thử nghiệm ban đầu.