You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by "mureinik (via GitHub)" <gi...@apache.org> on 2023/10/08 16:01:22 UTC

[PR] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

mureinik opened a new pull request, #4475:
URL: https://github.com/apache/eventmesh/pull/4475

   ### Motivation
   
   In its current form, the project has some JUnit 4 and some JUnit 5 (Jupiter) tests. This PR aims to align all the tests to a single modern framework, JUnit Jupiter, in order to make future development easier.
   
   ### Modifications
   
   As this PR is already pretty large as-is, it attempts to be non-opinionated and simply replace JUnit 4 calls with the closed JUnit Jupiter equivalents. Subsequent work may want to change some tests to take further advantage of JUnit Jupiter's features.
   
   This PR includes the following changes:
   
   1. Gradle dependencies:
      1. All the dependencies under `org.junit.jupiter` were consolidated to use the single artifact `org.junit.jupiter:junit-jupiter`.
      1. The `junit:junit` dependency was removed in favor of `org.junit.jupiter:junit-jupiter` mentioned in 1.i.
      1. The Mockito dependencies `org.mockito:mockito-core` and `org.mockito:mockito-inline` duplications were cleaned up, and each module was left only with the relevant dependency.
      1. The `org.mockito:mockito-junit-jupiter` dependency was added to provide the integration with Mockito.
      2. The `org.powermock:powermock-module-junit4` dependency was removed.
      3. The `org.powermock:powermock-api-mockito2` dependency was removed.
   
   1. Annotations
      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.AfterEach` was used as a drop-in replacement for `org.junit.After`.
      1. `org.junit.jupiter.api.AfterAll` was used as a drop-in replacement for `org.junit.AfterClass`.
      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.junit.jupiter.api.Test` was used as a replacement for `org.junit.Test`, although with some caveats:
          1. For the simple case with no arguments, `org.junit.jupiter.api.Test` was used as a drop-in replacement for `org.junit.Test`.
          1. For the case where `org.junit.Test` was used with a `timeout` argument, a combination of `org.junit.jupiter.api.Test` and `org.junit.jupiter.api.Timeout` was used.
          1. For the case where `org.junit.Test` was used with an `expected` argument, `org.junit.jupiter.api.Test` was used, but the assertion on the exception begin thrown is done explicitly in the test's code, see 3.i. below.
      1.  `org.junit.jupiter.api.extension.ExtendWith` was used as a replacement for `org.junit.runner.RunWith` with an extension corresponding to the runner being replaced.
          1. `org.mockito.junit.jupiter.MockitoExtension` was used to provide the same functionality as `org.mockito.junit.MockitoJUnitRunner`. Since the extension is stricter than the runner, in some cases `org.mockito.junit.jupiter.MockitoSettings` was used to explicitly make the mocking more lenient.
          4.  `org.mockito.junit.jupiter.MockitoExtension` was used to replace usages of `org.powermock.modules.junit4.PowerMockRunner` and its associated annotations.
   
   1. Assertions
      1. `org.junit.jupiter.api.Assertions` was used as a drop-in replacement for `org.junit.Assert` for the case where the assertion was performed without a message.
      1. `org.junit.jupiter.api.Assertions` was used instead of `org.junit.Assert` in the cases where an assertion method was used with a message, but the argument were permuted to fit the new method's signature.
      1. `org.junit.jupiter.api.Assertions` does not have an equivalent of `org.junit.Asser`t's `assertThat` method, but luckily it was only used in a few places, and always used the `org.hamcrest.CoreMatchers.is` matcher. These assertions were rewritten as straight-forward `assertEquals` assertions.
      1. `org.junit.jupiter.api.Assertions` does not have an equivalent of `org.hamcrest.MatcherAssert`'s `assertThat` method, but luckily it was only used in a few places, and always used the `org.hamcrest.CoreMatchers.is` matcher. These assertions were rewritten as straight-forward `assertEquals` assertions.
      1. `org.junit.jupiter.api.Assertions`' `assertThrows` was used to assert an expected exception is thrown instead of using `org.junit.Test` with the `expected` annotation.
   
   1. Mocking
       1. Usages of `org.powermock.api.mockito.PowerMockito` were deemed to be unnescary, and replaced with straight-forward usages of `org.mockito.Mockito`.
       5. Usages of `org.powermock.reflect.Whitebox` were cleaned, and the `org.mockito.InjectMocks` was used instead in order to inject mocks to the object under test.
       6. 
   
   
   
   
   ### Documentation
   
   - Does this pull request introduce a new feature? no
   - If yes, how is the feature documented? not applicable
   - If a feature is not applicable for documentation, explain why? It's not an external facing feature, it's an internal re-working of the testing framework
   - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


Re: [PR] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

Posted by "pandaapo (via GitHub)" <gi...@apache.org>.
pandaapo commented on PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475#issuecomment-1752284121

   Welcome! Please create an issue and add "Fixes #{issue num}" to this PR description to link that issue.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

Posted by "Alonexc (via GitHub)" <gi...@apache.org>.
Alonexc commented on PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475#issuecomment-1752284025

   Need to create an issue for this pr and link to this pr.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475#issuecomment-1752242622

   ## [Codecov](https://app.codecov.io/gh/apache/eventmesh/pull/4475?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#4475](https://app.codecov.io/gh/apache/eventmesh/pull/4475?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (dff6f49) into [master](https://app.codecov.io/gh/apache/eventmesh/commit/c8b7916f76dfa7526ea427ebb98c831ca838f091?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (c8b7916) will **decrease** coverage by `0.02%`.
   > The diff coverage is `n/a`.
   
   > :exclamation: Current head dff6f49 differs from pull request most recent head b0969d7. Consider uploading reports for the commit b0969d7 to get more accurate results
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #4475      +/-   ##
   ============================================
   - Coverage     15.58%   15.56%   -0.02%     
   + Complexity     1475     1474       -1     
   ============================================
     Files           698      698              
     Lines         28205    28200       -5     
     Branches       2633     2631       -2     
   ============================================
   - Hits           4396     4390       -6     
   + Misses        23361    23359       -2     
   - Partials        448      451       +3     
   ```
   
   
   [see 9 files with indirect coverage changes](https://app.codecov.io/gh/apache/eventmesh/pull/4475/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

Posted by "mureinik (via GitHub)" <gi...@apache.org>.
mureinik commented on PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475#issuecomment-1753326205

   > ![image](https://user-images.githubusercontent.com/41445332/273508259-f9a391d2-c193-4c37-84ce-556322627a22.png)
   > 
   > Please update dependency in `tools/dependency-check/known-dependencies.txt`.
   
   @Pil0tXia once the explicit dependency on `junit:junit` was removed, the `runtimeClasspath` that this check depends on picked up all sorts of transitive dependencies that TBH shouldn't have been there in the first place (i.e., they were either completely redundant or should have been test dependencies).
   I've pushed an updated version of this PR, that I **think** fixes the issue


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4478] Upgrade JUnit to JUnit Jupiter (eventmesh)

Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm merged PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


Re: [PR] [ISSUE #4478] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

Posted by "mureinik (via GitHub)" <gi...@apache.org>.
mureinik commented on PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475#issuecomment-1753336751

   > LGTM. Please create a corresponding issue and standardize your PR title and `Fixes`.
   
   @Pil0tXia done.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] Upgrade testing framework to JUnit 5 Jupiter (eventmesh)

Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on PR #4475:
URL: https://github.com/apache/eventmesh/pull/4475#issuecomment-1752401136

   ![image](https://github.com/apache/eventmesh/assets/41445332/f9a391d2-c193-4c37-84ce-556322627a22)
   
   Please update dependency in `tools/dependency-check/known-dependencies.txt`.


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org