Skip to content

Commit

Permalink
[FLINK-23255][test] Introduce JUnit 5 dependencies (apache#16551)
Browse files Browse the repository at this point in the history
[FLINK-23255][test] Introduce JUnit 5 dependencies.

All existing JUnit4 tests are run through the vintage runner of JUnit5.
  • Loading branch information
PatrickRen committed Aug 10, 2021
1 parent 760fa44 commit f8ce4d7
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ under the License.
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-kafka-test_${scala.binary.version}</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ under the License.
<artifactId>flink-shaded-jackson</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
5 changes: 3 additions & 2 deletions flink-end-to-end-tests/flink-end-to-end-tests-hbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ under the License.
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

<!--using hbase shade jar to execute end-to-end test-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ under the License.
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
Expand Down
5 changes: 2 additions & 3 deletions flink-end-to-end-tests/flink-streaming-kinesis-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ under the License.
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

Expand Down
17 changes: 0 additions & 17 deletions flink-table/flink-sql-parser-hive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ under the License.
<scope>test</scope>
<type>test-jar</type>
</dependency>
<!-- Because Calcite tests use Junit5 and we extend from its SqlParserTest,
we need the Junit5 runner. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<!-- As we switched to JUnit5 runner to use the Calcite tests infrastructure we need
to add this dependency to make our own Junit4 tests compatible with the Junit5
environment.-->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
17 changes: 0 additions & 17 deletions flink-table/flink-sql-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,6 @@ under the License.
<scope>test</scope>
<type>test-jar</type>
</dependency>
<!-- Because Calcite tests use Junit5 and we extend from its SqlParserTest,
we need the Junit5 runner. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<!-- As we switched to JUnit5 runner to use the Calcite tests infrastructure we need
to add this dependency to make our own Junit4 tests compatible with the Junit5
environment.-->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
11 changes: 8 additions & 3 deletions flink-test-utils-parent/flink-connector-test-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
14 changes: 11 additions & 3 deletions flink-test-utils-parent/flink-test-utils-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,29 @@ under the License.

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions flink-test-utils-parent/flink-test-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ under the License.
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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:https://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.
*/

package org.apache.flink.test.junit5;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/** Temporary JUnit 5 tests for validating JUnit jupiter engine truly works. */
public class JUnitJupiterTest {
@Test
@DisplayName("Assumption and Assertion Test")
public void assumptionAssertionTest() {
assumeTrue(true, "This case is absolutely true");
assertTrue(true, "This case is absolutely true");
}

@ParameterizedTest
@DisplayName("Parameterized Test")
@ValueSource(strings = {"racecar", "radar", "able was I ere I saw elba"})
public void parameterizedTest(String word) {
assertTrue(isPalindrome(word), "The string in parameter should be palindrome");
}

@TestFactory
@DisplayName("Dynamic Test")
Collection<DynamicTest> dynamicTest() {
String word = "madam";
String anotherWord = "flink";
return Arrays.asList(
DynamicTest.dynamicTest("1st dynamic test", () -> assertTrue(isPalindrome(word))),
DynamicTest.dynamicTest(
"2nd dynamic test", () -> assertFalse(isPalindrome(anotherWord))));
}

private boolean isPalindrome(String word) {
return StringUtils.reverse(word).equals(word);
}
}
25 changes: 19 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ under the License.
<avro.version>1.10.0</avro.version>
<javax.activation.api.version>1.2.0</javax.activation.api.version>
<jaxb.api.version>2.3.1</jaxb.api.version>
<junit.version>4.13.2</junit.version>
<junit4.version>4.13.2</junit4.version>
<junit5.version>5.7.2</junit5.version>
<mockito.version>2.21.0</mockito.version>
<powermock.version>2.0.4</powermock.version>
<hamcrest.version>1.3</hamcrest.version>
Expand Down Expand Up @@ -185,11 +186,15 @@ under the License.
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<type>jar</type>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -559,10 +564,18 @@ under the License.
</dependency>

<!-- For dependency convergence -->
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit5.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<version>${junit4.version}</version>
</dependency>

<!-- Make sure we use a consistent commons-cli version throughout the project -->
Expand Down Expand Up @@ -1520,7 +1533,7 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>2.22.2</version>
<configuration>
<forkCount>${flink.forkCount}</forkCount>
<reuseForks>${flink.reuseForks}</reuseForks>
Expand Down

0 comments on commit f8ce4d7

Please sign in to comment.