You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Claus Ibsen <fo...@opensymphony.com> on 2007/03/18 12:52:37 UTC

Unittest - catch 22

Hi

I have setup a local developer environment for Struts2 and clover to report on the unit tests.

When the unit tests are executed they are setup to only log at WARN level (log4j.properties in core/test/resources folder). In clover there are some log output at DEBUG level that are not tested and I changed the log4j.properties to include this line:

# set to lowest debug level to also execute debug code during unit testing to ensure it works also
log4j.logger.org.apache.struts2=TRACE

Now we have tests failing since some of the unit tests are using easymock or jmock and the predictions are now screwed due a different log4j level.

What's the S2 developers point of view on this? Should we assume that debug logging just works and thus run unit tests at current WARN level? 

The current unit tests are failing since we are debugging some more info at DEBUG level at thus calls some methods that jmock did not expect. My own point is that the current unit tests are correct and that in an ideal world jmock would not fail just because we log some debug information. But it would be nice to run unit tests at TRACE level to run through all the code as possible.


[surefire] Running org.apache.struts2.portlet.PortletRequestMapTest
[surefire] Tests run: 6, Failures: 5, Errors: 0, Time elapsed: 0,016 sec <<<<<<<< FAILURE !!

org.jmock.core.DynamicMockError: testPut: no match found
Invoked: javax.portlet.PortletRequest.getParameterMap()
Allowed:
expected once: setAttribute( eq(<testAttribute>), eq(<testValue>) ), is void
expected once: getAttribute( eq(<testAttribute>) ), returns <testValue>

	at org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
	at org.jmock.core.CoreMock.invoke(Unknown Source)
	at $Proxy34.getParameterMap(Unknown Source)
	at org.apache.struts2.portlet.PortletRequestMap.<init>(PortletRequestMap.java:54)
	at org.apache.struts2.portlet.PortletRequestMapTest.testPut(PortletRequestMapTest.java:64)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=71345&messageID=133427#133427


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Unittest - catch 22

Posted by Nils-Helge Garli <ni...@gmail.com>.
It's definetively a weakness in the tests, and illustrates how fragile
unit testing with mock objects is. Even though testing of the debug
logging might not be that interesting, these tests will proably have
to be frequently updated when changes occur in the code they test. So
my point of view is that they should be fixed and made more robust.

Nils-H

On 3/18/07, Claus Ibsen <fo...@opensymphony.com> wrote:
> Hi
>
> I have setup a local developer environment for Struts2 and clover to report on the unit tests.
>
> When the unit tests are executed they are setup to only log at WARN level (log4j.properties in core/test/resources folder). In clover there are some log output at DEBUG level that are not tested and I changed the log4j.properties to include this line:
>
> # set to lowest debug level to also execute debug code during unit testing to ensure it works also
> log4j.logger.org.apache.struts2=TRACE
>
> Now we have tests failing since some of the unit tests are using easymock or jmock and the predictions are now screwed due a different log4j level.
>
> What's the S2 developers point of view on this? Should we assume that debug logging just works and thus run unit tests at current WARN level?
>
> The current unit tests are failing since we are debugging some more info at DEBUG level at thus calls some methods that jmock did not expect. My own point is that the current unit tests are correct and that in an ideal world jmock would not fail just because we log some debug information. But it would be nice to run unit tests at TRACE level to run through all the code as possible.
>
>
> [surefire] Running org.apache.struts2.portlet.PortletRequestMapTest
> [surefire] Tests run: 6, Failures: 5, Errors: 0, Time elapsed: 0,016 sec <<<<<<<< FAILURE !!
>
> org.jmock.core.DynamicMockError: testPut: no match found
> Invoked: javax.portlet.PortletRequest.getParameterMap()
> Allowed:
> expected once: setAttribute( eq(<testAttribute>), eq(<testValue>) ), is void
> expected once: getAttribute( eq(<testAttribute>) ), returns <testValue>
>
>         at org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
>         at org.jmock.core.CoreMock.invoke(Unknown Source)
>         at $Proxy34.getParameterMap(Unknown Source)
>         at org.apache.struts2.portlet.PortletRequestMap.<init>(PortletRequestMap.java:54)
>         at org.apache.struts2.portlet.PortletRequestMapTest.testPut(PortletRequestMapTest.java:64)
> ---------------------------------------------------------------------
> Posted via Jive Forums
> http://forums.opensymphony.com/thread.jspa?threadID=71345&messageID=133427#133427
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org