KittehIRCClientLib icon indicating copy to clipboard operation
KittehIRCClientLib copied to clipboard

Migrate tests to modern JUnit Jupiter

Open mureinik opened this issue 4 years ago • 2 comments

The project currently uses the outdated JUnit 4.13.2. In order to make it easier to write tests and easier for future contributors to easily start working with the project, this patch migrates the test suite to the modern JUnit Jupiter.

This patch contains the following changes:

  • Dependencies:

    • The junit:junit:4.13.2 dependency was replaced with org.junit.jupiter:junit-jupiter:5.8.1
    • Unlike JUnit 4, JUnit Jupiter does not bundle the hamcrest library, so the explicit dependency org.hamcrest:hamcrest:2.2 was added
  • Annotations

    • org.junit.jupiter.api.BeforeEach was used as a drop-in replacement for org.junit.Before
    • org.junit.jupiter.api.Test was used as a drop-in replacement for org.junit.Test without arguments. See "Assertions" below for handling of org.junit.Test with an "expected" argument
  • Assertions

    • org.junit.jupiter.api.Assertions was used as a drop-in replacement for org.junit.Assert in the cases the "message" argument was not used. In the cases a "message" argument was used it was moved to be the last argument instead of the first argument
    • org.hamcrest.MatcherAssert#assertThat was used as a drop-in replacement for org.junit.Assert#assertThat
    • org.junit.jupiter.api.Assertions#assertThrows was used to assert cases where a method call should throw an exception instead of passing an "expected" argument to the @Test annotation. As a side bonus, this also makes the tests stricter, as it asserts the actual method call threw the expected exception and not the code used to set up its arguments/environment.
  • Misc

    • Tests using org.junit.rules.TemporaryFolder were rewritten to use the similar org.junit.jupiter.api.io.TempDir. While these two classes conceptually have the same functionality their APIs are different, and this is not a drop-in replacement.

mureinik avatar Oct 01 '21 21:10 mureinik

This seems reasonable to me! I just might take a bit to get around to reviewing so I'm throwing up the accepted label in celebration of hacktoberfest in the mean time :)

mbax avatar Oct 01 '21 22:10 mbax

Much appreciated!

I'm fully aware it's finiky to review, but I couldn't think of a reasonable way to make this PR any smaller - at least not without doing half a job, and leaving the project in a half JUnit 4 half JUnit Jupiter mess.

mureinik avatar Oct 01 '21 23:10 mureinik