我有 Spring 启动应用程序和使用空手道测试。我使用log4j2进行日志记录。空手道使用logback作为日志库。我找到了这个链接,用于使用空手道进行log4j2的基本配置。但不幸的是,功能文件中的print语句没有写入控制台。
这是我打印到控制台的简单测试。
Scenario: Print to Console
* print 'Hello Word'
log4j2.properties文件
log4j.rootLogger = INFO, CONSOLE
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
正如你所看到的,我用这个代码排除了空手道的logback依赖项
testImplementation('com.intuit.karate:karate-junit5:0.9.6') {
exclude module: "logback-classic"
}
testImplementation('com.intuit.karate:karate-apache:0.9.6') {
exclude module: "logback-classic"
}
渐变生成文件
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id "org.openapi.generator" version "4.3.1"
//id 'war'
}
group = 'test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
implementation('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
implementation('org.springframework.boot:spring-boot-starter-validation') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
implementation('org.springframework.boot:spring-boot-starter-quartz'){
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation 'org.mapstruct:mapstruct:1.4.0.Final'
implementation 'org.zalando:jackson-datatype-money:1.2.0'
compileOnly 'org.projectlombok:lombok'
implementation 'javax.validation:validation-api:2.0.0.Final'
implementation 'com.vladmihalcea:hibernate-types-52:2.9.13'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
implementation 'io.swagger:swagger-annotations:1.5.9'
implementation 'org.javamoney:moneta:1.4.2'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation('com.intuit.karate:karate-junit5:0.9.6') {
exclude module: "logback-classic"
}
testImplementation('com.intuit.karate:karate-apache:0.9.6') {
exclude module: "logback-classic"
}
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
}
test {
useJUnitPlatform()
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "test"
}
bootRun {
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "dev"
}
sourceSets {
test {
resources {
srcDir file('src/test/java')
exclude '**/*.java'
}
}
}
测试等级:
import com.intuit.karate.junit5.Karate;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class RunAllKarateTest {
@LocalServerPort
private int port;
@BeforeEach
void setUp() {
System.getProperties().setProperty("server.port", String.valueOf(port));
}
@Karate.Test
Karate runAll() {
return Karate.run().relativeTo(getClass());
}
}
空手道配置
function fn() {
var port = karate.properties['server.port'];
if (!port) {
port = 8080;
}
var config = {
baseUrl : 'http://localhost:'+port,
uuid: function(){ return java.util.UUID.randomUUID() + '' },
isoDateTime: function(){ return java.time.OffsetDateTime.now().format(java.time.format.DateTimeFormatter.ISO_DATE_TIME)}
};
return config;
}
这是报告截图
1条答案
按热度按时间x9ybnkn61#
它在更改log4j2.properties文件的配置后开始工作
新配置如下: