Hi, all,

Apache Flink is using JUnit for unit tests and integration tests widely in
the project, however, it binds to the legacy JUnit 4 deeply. It is
important to migrate existing cases to JUnit 5 in order to avoid splitting
the project into different JUnit versions.

Qingsheng Ren and I have conducted some trials about the JUnit 5 migration,
but there are too many modules that need to migrate. We would like to get
more help from the community. It is planned to migrate module by module,
and a JUnit 5 migration guide
<https://docs.google.com/document/d/1514Wa_aNB9bJUen4xm5uiuXOooOJTtXqS_Jqk9KJitU/edit?usp=sharing>[1]
has been provided to new helpers on the cooperation method and how to
migrate.

There are still some problem to discuss:

1. About parameterized test:

Some test classes inherit from other base test classes. We have discussed
different situations in the guide, but the situation where a parameterized
test subclass inherits from a non parameterized parent class has not been
resolved.

In JUnit 4, the parent test class always has some test cases annotated by
@Test. And  the parameterized subclass will run these test cases in the
parent class in a parameterized way.

In JUnit 5, if we want a test case to be invoked multiple times, the test
case must be annotated by @TestTemplate. A test case can not be annotated
by both @Test and @TestTemplate, which means a test case can not be invoked
as both a parameterized test and a non parameterized test.

We thought of two ways to migrate this situation, but not good enough. Both
two ways will introduce redundant codes, and make it hard to maintain.

The first way is to change the parent class to a parameterized test and
replace @Test tests to @TestTemplate tests. For its non parameterized
subclasses, we provide them a fake parameter method, which will provide
nothing.

The second way is to change the parameterized subclasses. We should
override all @Test tests in the parent class and annotate them with
@TestTemplate, these methods in the parameterized subclass should invoke
the same method in its parent class.


2. About PowerMock:

According to the code style rules[2] of Flink project, it’s discouraged to
use mockito for test cases, as well as Powermock, an extension of mockito.
Considering the situation that PowerMock lacks JUnit 5 support [3], we
suggest rewriting Powermock-based test class (~10 classes) with reusable
test implementations, and finally deprecate Powermock from the project.


3. Commit Author:

JUnit 5 migration will cause a lot of changed codes. Maybe we should use a
common author for the JUnit 5 migration commits.

Looking forward to your suggestions, thanks!

Best,

Hang

[1]
https://docs.google.com/document/d/1514Wa_aNB9bJUen4xm5uiuXOooOJTtXqS_Jqk9KJitU/edit?usp=sharing

[2]
https://flink.apache.org/contributing/code-style-and-quality-common.html#avoid-mockito---use-reusable-test-implementations


[3] https://github.com/powermock/powermock/issues/929

Reply via email to