Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-35490] Migrate tests to JUnit 5 and AssertJ #3742

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yuxiqian
Copy link
Contributor

This is a sequel PR based on @morazow's great work in #3395.

Currently, there are way too many unit tests and assertion frameworks, including JUnit-4 style Assert, JUnit-5 style Assertions, Hamcrest Matchers, AssertJ fluent assertions. JUnit 4, 5 (Jupier and Vintage) test frameworks are also used altogether, which is prone to mistakes.

Among all these solutions, AssertJ is generally regarded as the most readable and expressive, and used as the assertion standard in many other projects like Apache Iceberg.

This PR migrates all existing test cases to JUnit 5 + AssertJ combination, with an enforced rule defined in spotless style check to forbid using any other testing / asserting frameworks.

@yuxiqian
Copy link
Contributor Author

yuxiqian commented Nov 20, 2024

Most changes are just repetitive while some needs more attention:

  • Created wrapper classes AbstractTestBaseProxy because Flink's original version was targeted to JUnit 4
  • Created ExternalResourceProxy and StaticExternalResourceProxy to use JUnit 4 style @Rules and @ClassRules as JUnit 5 Extensions
  • Modified checkstyle.xml to forbid using any other testing / asserting frameworks (copied from https://github.com/apache/iceberg/blob/main/.baseline/checkstyle/checkstyle.xml)

cc @GOODBOY008 @whhe @ruanhang1993 @morazow

@yuxiqian yuxiqian force-pushed the FLINK-35490 branch 2 times, most recently from b56570d to a4f142c Compare November 20, 2024 09:32
Copy link
Contributor

@morazow morazow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yuxiqian 🚀 This is massive effort, thanks a lot!

I have added some suggestions, I will go over it again later on. Let's try to get this finalized soon

assertTrue(expected != null && actual != null);
assertEquals(expected.size(), actual.size());
assertArrayEquals(expected.toArray(new String[0]), actual.toArray(new String[0]));
Assertions.assertThat(actual).containsExactlyInAnyOrderElementsOf(expected);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return Arrays.asList("1.19.1", "1.20.0");
if (Objects.isNull(flinkVersion)) {
throw new IllegalArgumentException(
"No Flink version specified to run this test. Please use -DspecifiedFlinkVersion to pass one.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous test has default value. But it is good idea to throw here, since the release cycle is very frequent nowadays 👍

@yuxiqian yuxiqian force-pushed the FLINK-35490 branch 2 times, most recently from 2797740 to 15b3ef2 Compare December 3, 2024 02:14
@yuxiqian
Copy link
Contributor Author

yuxiqian commented Dec 3, 2024

Thanks for the quick review! Addressed comments and resolved conflicts.

Signed-off-by: yuxiqian <[email protected]>

# Conflicts:
#	flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-elasticsearch/pom.xml
#	flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-starrocks/pom.xml
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-db2-cdc/src/test/java/org/apache/flink/cdc/connectors/db2/table/Db2ConnectorITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mongodb-cdc/src/test/java/org/apache/flink/cdc/connectors/mongodb/table/MongoDBConnectorITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mongodb-cdc/src/test/java/org/apache/flink/cdc/connectors/mongodb/table/MongoDBRegexFilterITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/java/org/apache/flink/cdc/connectors/mysql/table/MySqlConnectorITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-oracle-cdc/src/test/java/org/apache/flink/cdc/connectors/oracle/table/OracleConnectorITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-postgres-cdc/src/test/java/org/apache/flink/cdc/connectors/postgres/table/PostgreSQLConnectorITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-postgres-cdc/src/test/java/org/apache/flink/cdc/connectors/postgres/table/PostgreSQLSavepointITCase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-sqlserver-cdc/src/test/java/org/apache/flink/cdc/connectors/sqlserver/table/SqlServerConnectorITCase.java
#	flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/pom.xml
#	flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/src/test/java/org/apache/flink/cdc/pipeline/tests/utils/PipelineTestEnvironment.java
#	flink-cdc-e2e-tests/flink-cdc-source-e2e-tests/src/test/java/org/apache/flink/cdc/connectors/tests/utils/FlinkContainerTestEnvironment.java

# Conflicts:
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/java/org/apache/flink/cdc/connectors/mysql/table/MySqlConnectorITCase.java

# Conflicts:
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/java/org/apache/flink/cdc/connectors/mysql/source/assigners/state/PendingSplitsStateSerializerTest.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-oceanbase-cdc/src/test/java/org/apache/flink/cdc/connectors/oceanbase/table/OceanBaseMySQLModeITCase.java

# Conflicts:
#	flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/source/assigner/state/PendingSplitsStateSerializerTest.java

# Conflicts:
#	flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/GenericConnectionPoolTest.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/MySqlChangeEventSourceExampleTest.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/source/assigner/state/PendingSplitsStateSerializerTest.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/source/meta/split/SourceSplitSerializerTest.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/testutils/UniqueDatabase.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/java/org/apache/flink/cdc/connectors/mysql/source/assigners/state/PendingSplitsStateSerializerTest.java
#	flink-cdc-connect/flink-cdc-source-connectors/flink-connector-postgres-cdc/src/test/java/org/apache/flink/cdc/connectors/postgres/source/fetch/PostgresScanFetchTaskTest.java
#	flink-cdc-e2e-tests/flink-cdc-source-e2e-tests/src/test/java/org/apache/flink/cdc/connectors/tests/OracleE2eITCase.java
#	flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/parser/JaninoCompilerTest.java
#	flink-cdc-runtime/src/test/java/org/apache/flink/cdc/runtime/parser/TransformParserTest.java

# Conflicts:
#	flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/src/test/java/org/apache/flink/cdc/pipeline/tests/MysqlE2eITCase.java
Signed-off-by: yuxiqian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment