Thanks for starting this discussion Francesco. I think there is a lot of
value in consistency because it makes it a lot easier to navigate and
contribute to the code base. The testing tools are definitely one important
aspect of consistency.

It is a bit unfortunate that we have tests that follow different patterns.
This, however, is mainly due to organic growth. I think the community
started with Junit4, then we chose to use Hamcrest because of its better
expressiveness. Most recently, there was an effort started that aimed at
switching over to Junit5 [1, 2]. @Arvid Heise <ar...@apache.org> knows more
about the current status.

Personally, I don't have a strong preference for which testing tools to
use. The important bit is that we agree as a community, then document the
choice and finally stick to it. So before starting to use assertj, we
should probably align with the folks working on the Junit5 effort first.

[1] https://lists.apache.org/thread/jsjvc2cqb91pyh47d4p6olk3c1vxqm3w
[2] https://lists.apache.org/thread/d9y5tzcl8wpk6ozmf8575qfzww450jpk

Cheers,
Till

On Fri, Nov 12, 2021 at 3:41 PM David Anderson <dander...@apache.org> wrote:

> For what it's worth, I recently rewrote all of the tests in flink-training
> to use assertj, removing a mixture of junit4 assertions and hamcrest in the
> process. I chose assertj because I found it to be more expressive and made
> the tests more readable.
>
> +1 from me
>
> David
>
> On Fri, Nov 12, 2021 at 10:03 AM Francesco Guardiani <
> france...@ververica.com> wrote:
>
> > Hi all,
> >
> > I wonder If we have a convention of the testing tools (in particular
> > assertions) to use in our tests. If not, are modules free to decide on a
> > convention on their own?
> >
> > In case of table, we have a mixed bag of different assertions of all
> kinds,
> > sometimes mixed even in the same test:
> >
> >    - Assertions from junit 4
> >    - Assertions from junit 5
> >    - Hamcrest
> >    - Some custom assertions classes (e.g. RowDataHarnessAssertor)
> >    - assert instructions
> >
> > The result is that most tests are very complicated to read and
> understand,
> > and we have a lot of copy pasted "assertion methods" all around our
> > codebase.
> >
> > For table in particular, I propose to introduce assertj [1] and develop a
> > couple of custom assertions [2] for the types we use most in our tests,
> > e.g. Row, RowData, DataType, LogicalType, etc... For example:
> >
> > assertFalse(row.isNullAt(1));
> > assert row instanceof GenericRowData;
> > assertEquals(row.getField(1),
> TimestampData.ofEpochMillis(expectedMillis));
> >
> > Could be:
> >
> > assertThat(row)
> >   .getField(1, TimestampData.class)
> >   .isEqualToEpochMillis(expectedMillis)
> >
> > We could have these in table-common so every part of the table stack can
> > benefit from it. Of course we can't take all our tests and convert them
> to
> > the new assertions, but as a policy we can enforce to use the new
> > assertions convention for every new test or for every test we modify in
> > future PRs.
> >
> > What's your opinion about it? Do you agree to have such kind of policy of
> > using the same assertions? If yes, do you like the idea of using assertj
> to
> > implement such policy?
> >
> > FG
> >
> > [1] A library for assertions https://assertj.github.io, already used by
> > the
> > pulsar connector
> > [2]
> https://assertj.github.io/doc/#assertj-core-custom-assertions-creation
> > --
> >
> > Francesco Guardiani | Software Engineer
> >
> > france...@ververica.com
> >
> >
> > <https://www.ververica.com/>
> >
> > Follow us @VervericaData
> >
> > --
> >
> > Join Flink Forward <https://flink-forward.org/> - The Apache Flink
> > Conference
> >
> > Stream Processing | Event Driven | Real Time
> >
> > --
> >
> > Ververica GmbH | Invalidenstrasse 115, 10115 Berlin, Germany
> >
> > --
> >
> > Ververica GmbH
> >
> > Registered at Amtsgericht Charlottenburg: HRB 158244 B
> >
> > Managing Directors: Karl Anton Wehner, Holger Temme, Yip Park Tung Jason,
> > Jinwei (Kevin) Zhang
> >
>

Reply via email to