You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@opennlp.apache.org by "Jeff Zemerick (Jira)" <ji...@apache.org> on 2021/10/08 22:15:00 UTC
[jira] [Closed] (OPENNLP-1338) Refactor DummyNameFinder to improve
test logic
[ https://issues.apache.org/jira/browse/OPENNLP-1338?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jeff Zemerick closed OPENNLP-1338.
----------------------------------
Fix Version/s: 1.9.4
Resolution: Fixed
> 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
> Fix For: 1.9.4
>
>
> 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)