You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@opennlp.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/09/19 19:53:00 UTC

[jira] [Commented] (OPENNLP-1338) Refactor DummyNameFinder to improve test logic

    [ https://issues.apache.org/jira/browse/OPENNLP-1338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17417389#comment-17417389 ] 

ASF GitHub Bot commented on OPENNLP-1338:
-----------------------------------------

wx930910 opened a new pull request #396:
URL: https://github.com/apache/opennlp/pull/396


   ### Jira
   
   - [OPENNLP-1338](https://issues.apache.org/jira/browse/OPENNLP-1338)
   
   ### Description
   
   #### Replace test class [DummyNameFinder](https://github.com/apache/opennlp/blob/7286f9c804b65a4a1d771d3c984ea76516fc8141/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderEvaluatorTest.java#L95) by mocking object and improve test design
   <hr>
   
   ##### Motivation
   
   - Decouple test class `DummyNameFinder` from production interface `TokenNameFinder`.
   - Remove the redundant test child class `PrintingVisitor`
   - Remove the redundant overridden methods `clearAdaptiveData()`
   - Make testing logic more explict.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * Created mocking object to replace test subclass `DummyNameFinder`, decoupled test from production code.
    * Created method that return the mocking object for code reuse.
    * Add Mockito dependency.
   
   <hr>
   
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [x] Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
   
   - [x] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [x] Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
   - [x] Have you written or updated unit tests to verify your changes?
   - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file in opennlp folder?
   - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found in opennlp folder?
   
   ### Note:
   Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
   


-- 
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@opennlp.apache.org

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


> Refactor DummyNameFinder to improve test logic
> ----------------------------------------------
>
>                 Key: OPENNLP-1338
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1338
>             Project: OpenNLP
>          Issue Type: Improvement
>            Reporter: Xiao Wang
>            Priority: Minor
>
> h3. Description
> I noticed that there is a test class [DummyNameFinder|https://github.com/apache/opennlp/blob/7286f9c804b65a4a1d771d3c984ea76516fc8141/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderEvaluatorTest.java#L95] implements production interface [TokenNameFinder|https://github.com/apache/opennlp/blob/7286f9c804b65a4a1d771d3c984ea76516fc8141/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinder.java#L25] to assist testing  [Evaluator.evaluateSample(NameSample)|https://github.com/apache/opennlp/blob/7286f9c804b65a4a1d771d3c984ea76516fc8141/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java#L78]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
> h3. Current Implementation
>  * {{DummyNameFinder}} implements {{TokenNameFinder}} and overrides methods to return fixed object for {{find()}}.
>  * In test case, the child test class is used to assit testing by passing as a parameter to contructor of {{TokenNameFinderEvaluator}}.
> h3. Proposed Implementation
>  * Replace {{DummyNameFinder}} with a mocking object created by Mockito.
>  * Use method stub to control the behavior of {{find()}}.
>  * Create a method to return the mocking object for reusing.
> h3. Motivation
>  * Decouple test class {{DummyNameFinder}} from production interface {{TokenNameFinder}}.
>  * Remove the redundant test child class {{PrintingVisitor}}
>  * Remove the redundant overridden methods {{clearAdaptiveData()}}
>  * Make testing logic more explict.
> h3. More Thought
> * We can further improve the testing logic by creating mock object inside of the test case and only stub {{find(String[])}} method.



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