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

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

Xiao Wang created RNG-164:
-----------------------------

             Summary: 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


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)