Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't HttpClient tear down properly between unit tests in grails
    primarykey
    data
    text
    <p>I have two Controller unit tests and each one sets an HttpClient metaclass execute in setUp() like the following:</p> <pre><code>HttpClient.metaClass.execute = { HttpUriRequest request -&gt; &lt;return expected data for my tests&gt; } </code></pre> <p>Then I attempt to tear down the metaClass in tearDown() with the following code:</p> <pre><code>protected void tearDown() { super.tearDown() GroovySystem.metaClassRegistry.removeMetaClass(HttpClient.class) } </code></pre> <p>However only one of my unit tests passes because the return from the HttpClient is incorrect/unexpected. If I add the logic needed for both tests in the metaClass.execute of both tests I get no testing failures. However this is cumbersome and impractical, especially in an agile development environment.</p> <p>What am I doing wrong with trying to tear down this HttpClient metaclass registration? How can I troubleshoot this further?</p> <p>I'm currently using grails 1.3.7 on a CentOS 5 install.</p> <p><strong>Edit:</strong> I should clarify that my problem is that the metaClass override is causing issues between test <em>classes</em>, not test cases. We've been setting up the metaClass override so that it will return correct data for all of the test cases in a given class. So Test class A has the metaClass data for it's test cases and Test class B has the metaClass data for it's test cases. The issue is that since Test class A gets tested first, test class B ends up using the metaClass definition from test class A and fails because of this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload