You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2021/09/16 07:55:00 UTC

[jira] [Commented] (RNG-164) Refactor SimpleSampler in SamplerBaseTest.java to improve test logic

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

Alex Herbert commented on RNG-164:
----------------------------------

Adding a mocking framework to test that 4 methods in a deprecated abstract class correctly invoke 4 methods in a wrapped object appears to be adding complexity, rather than simplifying. IMO the change makes the test (currently only about 50 lines of code) less maintainable due to the higher entry point required by knowing best practice use of Mockito.

Decoupling the test class from the production class is not required here. The production class is deprecated and will not change until version 2.0 when it will be removed.

 

> Refactor SimpleSampler in SamplerBaseTest.java to improve test logic
> --------------------------------------------------------------------
>
>                 Key: RNG-164
>                 URL: https://issues.apache.org/jira/browse/RNG-164
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>            Reporter: Xiao Wang
>            Priority: Minor
>
> h3. Description
> I noticed that there is a test class [SimpleSampler|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java#L33] extends production class [SamplerBase|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L29] to assist testing  [nextDouble()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L44], [nextInt()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L51], [nextInt(int)|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L59] and [nextLong()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L66]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
> h3. Current Implementation
>  * {{SimpleSampler}} implements {{SamplerBase}} and overrides methods to call super methods defined in parent class.
>  * In test case, the child test class is used to test methods in parent class {{SamplerBase}}.
> h3. Proposed Implementation
>  * Replace {{SimpleSampler}} with a mocking object created by Mockito.
>  * Use method stub to control the behavior of the mocking object.
>  * Create a method to return the mocking object for reusing.
> h3. Motivation
>  * Decouple test class {{SimpleSampler}} from production class {{SamplerBase}}.
>  * Remove the redundant test child class {{SimpleSampler}}



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