You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2019/10/05 18:06:00 UTC

[jira] [Work logged] (CSV-252) Upgrade test framework to JUnit Jupiter

     [ https://issues.apache.org/jira/browse/CSV-252?focusedWorklogId=323963&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-323963 ]

ASF GitHub Bot logged work on CSV-252:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Oct/19 18:05
            Start Date: 05/Oct/19 18:05
    Worklog Time Spent: 10m 
      Work Description: mureinik commented on pull request #49: CSV-252: Upgrade to JUnit Jupiter
URL: https://github.com/apache/commons-csv/pull/49
 
 
   This PR upgrades the project's testing framework from JUnit 4.12 to the modern JUnit Jupiter 5.5.4.
   
   Since JUnit 5 Jupiter is not backwards compatible to JUnit 4.x (or even JUnit Vintage), this patch 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 PR includes the following changes:
   
   1. Maven dependency changes:
        1. `junit:junit` was replaced with `org.junit.jupiter:junit-jupiter`.
        1. `org.hamcrest:hamcrest` was introduced as an explicit dependency, since the project uses Hamcrest, and JUnit Jupiter does not bundle Hamcrest, unlike JUnit 4.x.
        1. The Mockito dependency was upgraded from `org.mockito.mockito-all:1.10.19` to `org.mockito:mockito-core:3.1.0`, which supports JUnit Jupiter.
   
    1. Annotations:
         1. `org.junit.jupiter.api.Test` was used as a drop in replacement for `org.juit.Test` without arguments. See 3.ii. for handling of `@Test` annotations with an `expected` argument.
        1. `org.junit.jupiter.api.BeforeEach` was used as a drop in replacement for `org.junit.Before`.
        1. `org.junit.jupiter.api.BeforeAll` was used as a drop in replacement for `org.junit.BeforeClass`.
        1. `org.junit.jupiter.api.Disabled` was used as a drop in replacement for `org.junit.Ignore`.
   
   1. 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 thrown instead of an `org.junit.Test` annotation with an `expected` argument. This technique has a couple of side bonuses. First, it makes 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. Second, it clarifies that some of the test code is unreachable (as a previous line already throws an exception), and can safely be removed in order to clean up the test. 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.hamcrest.MatcherAssert#assertThat` was used as a drop in replacement for `org.junit.Assert#assertThat`.
        1. `org.junit.jupiter.api.Assertions#assertNull` was used as a drop in replacement for `junit.framework.TestCase#assertNull`.
   
   1. Specific Changes:
        1. `CSVFileParserTest` was rewritten with JUnit Jupiter's `org.junit.jupiter.api.ParameterizedTest`.  Unlike JUnit 4's `org.junit.runners.Parameterized`, it cannot be used to inject arguments to a test's construct, and so the test can't be stateful. Instead, it was rewritten so every test receives the file as a parameter, and opens a reader on it itself. As a side bonus, this design makes it easier to close the reader and avoid leaving open file descriptors like the original test did.
   
   
   Closes CSV-252
 
----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 323963)
    Remaining Estimate: 0h
            Time Spent: 10m

> Upgrade test framework to JUnit Jupiter
> ---------------------------------------
>
>                 Key: CSV-252
>                 URL: https://issues.apache.org/jira/browse/CSV-252
>             Project: Commons CSV
>          Issue Type: Task
>          Components: Build
>            Reporter: Allon Mureinik
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Commons CSV's tests use JUnit 4.12, which is a tad outdated.
>  
> We should upgrade to the modern JUnit Jupiter and make it easier to write future tests. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)