[ 
https://issues.apache.org/jira/browse/COLLECTIONS-798?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xiao Wang updated COLLECTIONS-798:
----------------------------------
    Description: 
h3. Description

I noticed that there is a test class 
[TestBuilder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HasherBuilderTest.java#L41]
 implements production interface 
[Builder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L35]
 to assist testing methd [Builder:with(CharacterSequence, 
Charset)|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L73].
 This might not be the best priactice in unit testing and can be improved by 
leveraging mocking frameworks.

h3. Current Implementation
*  {{TestBuilder}} implements {{Builder}} and creates a new list {{items}} to 
keep tracking of the input parameters for {{with(byte[])}}.
* In test cases, after executing test target, the list will be used in 
assertion statement to check the input parameters of {{with(byte[])}}.

h3. Proposed Implementation
 * Replace {{TestBuilder}} with a mocking object created by Mockito.
 * Extract the attribute into test cases to keep tracking input parameters.
 * Use method stub to control the behavior of the mocking object.

h3. Motivation
 * Decouple test class {{TestBuilder}} from production interface {{Builder}}.
 * Make test logic more clear by using method stub instead of method overriding.
 * Make test condition more explict by use local variable in test case.

  was:
h3. Description

I noticed that there is a test class 
[TestBuilder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HasherBuilderTest.java#L41]
 implements production interface 
[Builder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L35]
 to assist testing methd [Builder:with(CharacterSequence, 
Charset)|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L73].
 This might not be the best priactice in unit testing and can be improved by 
leveraging mocking frameworks.

h3. Current Implementation
*  {{TestBuilder}} implements {{Builder}} and creates a new list {{items}} to 
keep tracking of the input parameters for {{with(byte[])}}.
* In test cases, after executing test target, the list will be used in 
assertion statement to check the input parameters of {{with(byte[])}}.

h3. Proposed Implementation
 * Replace {{TestBuilder}} with a mocking object created by Mockito.
 * Extract the attribute into test cases to keep tracking input parameters.
 * Use method stub to control the behavior of the mocking object.

h3. Motivation
 - Decouple test class {{TestBuilder}} from production interface {{Builder}}.
 - Make test logic more clear by using method stub instead of method overriding.
 - Make test condition more explict by use local variable in test case.


> Replace TestBuilder with mocking object to improve test design
> --------------------------------------------------------------
>
>                 Key: COLLECTIONS-798
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-798
>             Project: Commons Collections
>          Issue Type: Improvement
>            Reporter: Xiao Wang
>            Priority: Minor
>
> h3. Description
> I noticed that there is a test class 
> [TestBuilder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HasherBuilderTest.java#L41]
>  implements production interface 
> [Builder|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L35]
>  to assist testing methd [Builder:with(CharacterSequence, 
> Charset)|https://github.com/apache/commons-collections/blob/3aae82cbaaaf539bf3f54cd6a0679efc123f2c8e/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java#L73].
>  This might not be the best priactice in unit testing and can be improved by 
> leveraging mocking frameworks.
> h3. Current Implementation
> *  {{TestBuilder}} implements {{Builder}} and creates a new list {{items}} to 
> keep tracking of the input parameters for {{with(byte[])}}.
> * In test cases, after executing test target, the list will be used in 
> assertion statement to check the input parameters of {{with(byte[])}}.
> h3. Proposed Implementation
>  * Replace {{TestBuilder}} with a mocking object created by Mockito.
>  * Extract the attribute into test cases to keep tracking input parameters.
>  * Use method stub to control the behavior of the mocking object.
> h3. Motivation
>  * Decouple test class {{TestBuilder}} from production interface {{Builder}}.
>  * Make test logic more clear by using method stub instead of method 
> overriding.
>  * Make test condition more explict by use local variable in test case.



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

Reply via email to