[
https://issues.apache.org/jira/browse/CURATOR-616?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Xiao Wang updated CURATOR-616:
------------------------------
Description:
h3. Description
I noticed that there is a test class
[DummyLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java#L91]
implements production class
[PropertiesConfigurationLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java#L102]
to assist testing method [PropertiesConfiguration.propertyLoaded(String,
String,
Deque<URL>)|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java#L1467].
This might not be the best priactice in unit testing and can be improved by
leveraging mocking frameworks.
h3. Current Implementation
* {{DummyLayout}} extends {{PropertiesConfigurationLayout}} and creates a new
variable to keep tracking of the method invocation status for
{{load(PropertiesConfiguration, Reader)}}.
* In test cases, after executing
{{PropertiesConfiguration.propertyLoaded(String, String, Deque<URL>)}}, the new
variable will be used in assertion statement to check the execution status of
{{load(PropertiesConfiguration, Reader)}}.
h3. Proposed Implementation
* Replace {{DummyLayout}} with a mocking object created by Mockito.
* Remove the {{int}} variable that used to keep tracking the invocation times
of {{load(PropertiesConfiguration, Reader)}}.
* Use {{Mockito.verify()}} to check execution status of
{{load(PropertiesConfiguration, Reader)}}.
h3. Motivation
* Decouple test class `DummyLayout` from production class
`PropertiesConfigurationLayout`.
* Make test logic more clear by removing the overridden method in
{{DummyLayout}}.
* Make test condition more explict by directly using {{Mockito.verify()}} to
verify method execution status.
was:
h3. Description
I noticed that there is a test class
[DummyLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java#L91]
implements production class
[PropertiesConfigurationLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java#L102]
to assist testing method [PropertiesConfiguration.propertyLoaded(String,
String,
Deque<URL>)|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java#L1467].
This might not be the best priactice in unit testing and can be improved by
leveraging mocking frameworks.
h3. Current Implementation
* {{DummyLayout}} extends {{PropertiesConfigurationLayout}} and creates a new
variable to keep tracking of the method invocation status for
{{load(PropertiesConfiguration, Reader)}}.
* In test cases, after executing
{{PropertiesConfiguration.propertyLoaded(String, String, Deque<URL>)}}, the new
variable will be used in assertion statement to check the execution status of
{{load(PropertiesConfiguration, Reader)}}.
h3. Proposed Implementation
* Replace {{DummyLayout}} with a mocking object created by Mockito.
* Remove the {{int}} variable that used to keep tracking the invocation times
of {{load(PropertiesConfiguration, Reader)}}.
* Use {{Mockito.verify()}} to check execution status of
{{load(PropertiesConfiguration, Reader)}}.
h3. Motivation
* Decouple test class `DummyLayout` from production class
`PropertiesConfigurationLayout`.
* Make test logic more clear by removing the overridden method in
{{DummyLayout}}.
* Make test condition more explict by directly using {{Mockito.verify()}} to
verify method execution status.
> Refactor DummyLayout in TestPropertiesConfiguration to improve test design
> --------------------------------------------------------------------------
>
> Key: CURATOR-616
> URL: https://issues.apache.org/jira/browse/CURATOR-616
> Project: Apache Curator
> Issue Type: Improvement
> Components: Tests
> Reporter: Xiao Wang
> Priority: Minor
>
> h3. Description
> I noticed that there is a test class
> [DummyLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java#L91]
> implements production class
> [PropertiesConfigurationLayout|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java#L102]
> to assist testing method [PropertiesConfiguration.propertyLoaded(String,
> String,
> Deque<URL>)|https://github.com/apache/commons-configuration/blob/66b4f4eb73b276d041debaad80af3074ccb359bd/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java#L1467].
> This might not be the best priactice in unit testing and can be improved by
> leveraging mocking frameworks.
> h3. Current Implementation
> * {{DummyLayout}} extends {{PropertiesConfigurationLayout}} and creates a new
> variable to keep tracking of the method invocation status for
> {{load(PropertiesConfiguration, Reader)}}.
> * In test cases, after executing
> {{PropertiesConfiguration.propertyLoaded(String, String, Deque<URL>)}}, the
> new variable will be used in assertion statement to check the execution
> status of {{load(PropertiesConfiguration, Reader)}}.
> h3. Proposed Implementation
> * Replace {{DummyLayout}} with a mocking object created by Mockito.
> * Remove the {{int}} variable that used to keep tracking the invocation
> times of {{load(PropertiesConfiguration, Reader)}}.
> * Use {{Mockito.verify()}} to check execution status of
> {{load(PropertiesConfiguration, Reader)}}.
> h3. Motivation
> * Decouple test class `DummyLayout` from production class
> `PropertiesConfigurationLayout`.
> * Make test logic more clear by removing the overridden method in
> {{DummyLayout}}.
> * Make test condition more explict by directly using {{Mockito.verify()}} to
> verify method execution status.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)