commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <>
Subject [jira] [Work logged] (IO-628) Migration Commons-IO to JUnit Jupiter
Date Tue, 01 Oct 2019 08:41:00 GMT


ASF GitHub Bot logged work on IO-628:

                Author: ASF GitHub Bot
            Created on: 01/Oct/19 08:40
            Start Date: 01/Oct/19 08:40
    Worklog Time Spent: 10m 
      Work Description: mureinik commented on pull request #97: IO-628: Migration to JUnit
   This PR upgrades the project's testing framework from JUnit 4.12 to the modern JUnit Jupiter
   Since JUnit 5 Jupiter is not backwards compatible to JUnit 4.x (or even JUnit Vintage),
this PR is a bit large, even though a lot of the changes are merely cosmetic (such as changing
the argument order,
   see details below). In order to make the reviewer's task as easy as possible, this PR does
not presume to use JUnit Jupiter's best practices and all its new functionality, but only
to migrate the existing tests with as little change as possible. Following PRs may want to
improve the tests by using some of JUnit Jupiter's new  features.
   This patch includes the following changes:
   1. Maven dependency changes:
       1. `junit:junit` was replaced with `org.junit.jupiter:junit-jupiter`.
       1. `org.junit-pioneer:junit-pioneer` was introduced (see details below in section 2.vii.).
       1. The JaCoCo report was disabled by adding the `jacoco.skip` property. Note that this
report fails on the master branch too (e.g., see errors inline in,
but does not fail the build. With JUnit Jupiter there seem to be more of these errors, and
the jdk-ea build fails since the log file is exhausted (although all the test pass!). In order
to allow the build to pass, this (already broken) report was disabled.
   2. Annotations:
       1. `org.junit.jupiter.api.Test` was used as a drop in replacement for `org.juit.Test`
without arguments. See 3.ii. and 3.iii. for handling of `@Test` annotations with `expected`
and `timeout` arguments respectively.
       1. `org.junit.jupiter.params.ParameterizedTest` in conjunction with `org.junit.jupiter.params.provider.MethodSource`
was used to replace `org.juit.Test` in test classes run with `org.junit.runners.Parameterized`.
       1. `org.junit.runners.Parameterized.Parameters` annotations were removed, and the methods
annotated with them were written to match the signature expected of a `@MethodSource`.
       1. `org.junit.jupiter.api.BeforeEach` was used as an drop in replacement for `org.junit.Before`.
       1. `org.junit.jupiter.api.AfterEach` was used as a drop in replacement for `org.junit.After`.
       1. `org.junit.jupiter.api.Disabled` was used as a drop in replacement for `org.junit.Ignore`.
       1. `org.junitpioneer.jupiter.DefaultLocale` was used as a drop in replacement for ``.
This annotation comes from the JUnit Pioneer project, and while it isn't part of the actual
JUnit project, it's widely accepted as an extension library for JUnit, and is used in other
Apache Commons projects, such as Apache Commons Lang.
   3. Assertions:
       1. `org.junit.jupiter.api.Assertions`' methods were used as drop in replacements for
`org.junit.Assert`'s methods with the same name in the simple case of an assertion without
a message.  In the case of an assertion with a message, `org.junit.jupiter.api.Assertions`'
methods were used, but the argument order was changed - `Assert`'s methods take the message
as the first argument, while `Assertions`' methods take the message as the last argument.
       1. `org.junit.jupiter.api.Assertions#assertThrows` was used to assert that a specific
exception was throws instead of an `org.junit.Test` annotation with an `expected` argument.
This technique has a side bonus of making the tests slightly stricter, as now they can assert
the exception was thrown from a specific line and prevent false positives where the test's
"set-up" code accidentally threw that exception. The `throws` clauses of these methods were
cleaned up from exceptions that can no longer be thrown in order to avoid compilation warnings.
       1. `org.junit.jupiter.api.Assertions#assertTimeout` was used to assert a specific block
of code completes before a timeout is reach instead of an `org.junit.Test` annotation with
a `timeout` argument.
       1. `org.junit.jupiter.api.Assertions#fail` was used in order to explicitly fail a test
instead of throwing a `junit.framework.AssertionFailedError`.
   4. Assumptions
       1. `org.junit.jupiter.api.Assumptions`' methods were used as drop in replacements for
`org.junit.Assume`'s methods with the same name, but the argument order was changed - `Assume`'s
methods take the message as the first argument, while `Assumptions`' methods take the message
as the last argument.
   5. Rules
       1. `` was used instead of the `org.junit.rules.TemporaryFolder`
`@Rule`, and the code that used them was adapted accordingly. Note that `TempDir` is stricter
than the old `TemporaryFolder` rule, and will fail the test if any file in the temporary directory
cannot be deleted, and thus some tests required specific changes. See 6.ii. and 6.iii. for
additional details.
       1. `` was removed from the project,
and its functionality replaced by `org.junitpioneer.jupiter.DefaultLocale`.
   6. Specific changes:
       1. Parameters in JUnit Jupiter (such as those produced by `MethodSource`) can only
be applied to `@Test` methods, not to other lifecycle methods, such as `@BeforeEach`. Thus,
the design of `ReversedLinesFileReaderTestParamFile` had to be changed - instead of receiving
constructor arguments and storing a state in data members, it was rewritten to be stateless,
and manage all its resources in the single test method it has, `testDataIntegrityWithBufferedReader`.
As a side bonus, this change allows to narrow the scope of open resources, and close them
immediately after they are no longer needed, instead of preserving them in data members until
the `@After` method is called.
       1.  `TailerTest` opens multiple threads that hold open descriptors on files in the
temporary directory which prevent their deletion (at least in Windows), and would fail the
test when migrated to `@TempDir`. These threads had to be explicitly closed in order to allow
the tests to pass.
       1.  `FileUtilsCleanDirectoryTestCase`'s methods `testThrowsOnNullList` and `testThrowsOnCannotDeleteFile`
chmod the temporary directory and thus prevent files in it from being deleted at the end of
the test. A `finally` block was added to these tests in order to chmod the temporary directory
back to 755 and allow it to be deleted. In addition, the restriction of not running the test
on Windows was changed to use JUnit Jupiter's `@DisabledOnOs` annotation, in order to make
the test a tad easier to follow.
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

Issue Time Tracking

    Worklog Id:     (was: 321124)
    Time Spent: 2h 20m  (was: 2h 10m)

> Migration Commons-IO to JUnit Jupiter
> -------------------------------------
>                 Key: IO-628
>                 URL:
>             Project: Commons IO
>          Issue Type: Task
>          Components: Utilities
>            Reporter: Allon Mureinik
>            Priority: Minor
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
> Migrate the Commons IO project to the modern JUnit Jupiter framework (instead of JUnit
4 which it currently uses) in order to make it easier to maintain and for future contributors
to participate.

This message was sent by Atlassian Jira

View raw message