mirror of https://github.com/apache/kafka.git
MINOR: Add junit properties to display parameterized test names (#14687)
In many parameterized tests, the display name is broken. Example - `testMetadataFetch` appears as `[1] true`, `[2] false` [link](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14607/9/testReport/junit/org.apache.kafka.clients.producer/KafkaProducerTest/) This is because the constant in `@ParameterizedTest` ```java String DEFAULT_DISPLAY_NAME = "[{index}] {argumentsWithNames}"; ``` This PR adds a new `junit-platform.properties` which overrides to add a `{displayName}` which shows the `the display name of the method` For existing tests which override the name, should work as is. The precedence rules are explained > 1. `name` attribute in `@ParameterizedTest`, if present > 2. value of the `junit.jupiter.params.displayname.default` configuration parameter, if present > 3. `DEFAULT_DISPLAY_NAME` constant defined in `@ParameterizedTest` Source: https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests-display-names Sample test run output Before: `[1] true` [link](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14607/9/testReport/junit/org.apache.kafka.clients.producer/KafkaProducerTest/) After: `testMetadataExpiry(boolean).false` [link](https://ci-builds.apache.org/job/Kafka/job/kafka-pr/job/PR-14687/1/testReport/junit/org.apache.kafka.clients.producer/KafkaProducerTest/) Reviewers: Divij Vaidya <diviv@amazon.com>, Bruno Cadonna <cadonna@apache.org>, David Jacot <djacot@confluent.io>
This commit is contained in:
parent
b888fa1ec9
commit
bdf6d46b41
|
|
@ -0,0 +1,15 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
junit.jupiter.params.displayname.default = "{displayName}.{argumentsWithNames}"
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
junit.jupiter.params.displayname.default = "{displayName}.{argumentsWithNames}"
|
||||
|
|
@ -36,6 +36,7 @@ import org.apache.kafka.test.TestUtils;
|
|||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
|
@ -54,12 +55,19 @@ public class StandbyTaskCreationIntegrationTest {
|
|||
|
||||
public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
|
||||
|
||||
private String safeTestName;
|
||||
|
||||
@BeforeAll
|
||||
public static void startCluster() throws IOException, InterruptedException {
|
||||
CLUSTER.start();
|
||||
CLUSTER.createTopic(INPUT_TOPIC, 2, 1);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(final TestInfo testInfo) {
|
||||
safeTestName = safeUniqueTestName(getClass(), testInfo);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void closeCluster() {
|
||||
CLUSTER.stop();
|
||||
|
|
@ -79,7 +87,6 @@ public class StandbyTaskCreationIntegrationTest {
|
|||
}
|
||||
|
||||
private Properties streamsConfiguration(final TestInfo testInfo) {
|
||||
final String safeTestName = safeUniqueTestName(getClass(), testInfo);
|
||||
final Properties streamsConfiguration = new Properties();
|
||||
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
|
||||
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.kafka.clients.producer.ProducerRecord;
|
|||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
import org.apache.kafka.common.Metric;
|
||||
import org.apache.kafka.common.TopicPartition;
|
||||
import org.apache.kafka.common.Uuid;
|
||||
import org.apache.kafka.common.errors.TimeoutException;
|
||||
import org.apache.kafka.common.header.Headers;
|
||||
import org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataPartitionState;
|
||||
|
|
@ -241,20 +242,24 @@ public class IntegrationTestUtils {
|
|||
* Used by tests migrated to JUnit 5.
|
||||
*/
|
||||
public static String safeUniqueTestName(final Class<?> testClass, final TestInfo testInfo) {
|
||||
final String displayName = testInfo.getDisplayName();
|
||||
final String methodName = testInfo.getTestMethod().map(Method::getName).orElse("unknownMethodName");
|
||||
final String testName = displayName.contains(methodName) ? methodName : methodName + displayName;
|
||||
return safeUniqueTestName(testClass, testName);
|
||||
return sanitize(methodName + Uuid.randomUuid().toString());
|
||||
}
|
||||
|
||||
private static String safeUniqueTestName(final Class<?> testClass, final String testName) {
|
||||
return (testClass.getSimpleName() + testName)
|
||||
.replace(':', '_')
|
||||
.replace('.', '_')
|
||||
.replace('[', '_')
|
||||
.replace(']', '_')
|
||||
.replace(' ', '_')
|
||||
.replace('=', '_');
|
||||
return sanitize(testClass.getSimpleName() + testName);
|
||||
}
|
||||
|
||||
private static String sanitize(final String str) {
|
||||
return str
|
||||
// The `-` is used in Streams' thread name as a separator and some tests rely on this.
|
||||
.replace('-', '_')
|
||||
.replace(':', '_')
|
||||
.replace('.', '_')
|
||||
.replace('[', '_')
|
||||
.replace(']', '_')
|
||||
.replace(' ', '_')
|
||||
.replace('=', '_');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue