surefire, PowerMock, and verifyStatic intermittent failures
<p>We are using maven and surefire 2.19 for Junit 4.11 tests.  When we run with our IDEs or from the command line we don't see any failures.  Yet intermittently when using Jenkins a couple of our tests will failure a verifyStatic assertion.</p>

<p>Here's a snippet:</p>

<pre><code>verifyStatic(times(1));
AClass.someStaticMethod(aUrl);
</code></pre>

<p>surefire sometimes reports:</p>

<pre><code>[java] Failed tests: 
[java]   AClass.someStaticMethod:55 
[java] Wanted but not invoked AClass.someStaticMethod(
[java]     "http://foo.com/artwork.png"
[java] );
[java] Actually, there were zero interactions with this mock.
</code></pre>

<p>I've tired going single threaded on the tests thinking that's what our IDEs are doing but that didn't help:</p>

<pre><code>&lt;reuseForks&gt;false&lt;/reuseForks&gt;
&lt;forkCount&gt;1&lt;/forkCount&gt;
</code></pre>

<p>Any suggestions on what could be happening and how to fix it?</p>

<p>Update:</p>

<p>I am calling mockStatic(AClass.class) before this test runs.</p>

<p>Also, I've been able to reproduce this on the command line by setting up a while loop.</p>

<pre><code>while [ $? -eq 0 ]; do ./mvnvm -T 8 clean &amp;&amp; \
./mvnvm -T 8 -b multithreaded -am -Dtest=AClassTests \
-DfailIfNoTests=false -Dmaven.test.skip=false -pl MyProject test; done
</code></pre>

<p>Eventually in this loop I will get the test to fail.  Now I have to figure how to detect the failure before it happens and get a debugger attached.</p>

<p>Update 2:</p>

<p>I can easily reproduce this problem after a maven clean, seems to happen the first run after a clean.</p>

<p>Sorry, I lied.  Thread.sleep has no effect on this.</p>

<p>Update 3:</p>

<p>as per update 2, Thread.sleep has no effect.</p>

<p>Arthor, here is a bit more code:</p>

<pre><code>PowerMockito.mockStatic(ImageUtil.class);
Mockito.when(ImageUtil.getImageDetail(imageUrl)).thenReturn(detail);

ValidationCommand command = new ValidationCommand();
command.execute(validationContext);

Thread.sleep(1000);

PowerMockito.verifyStatic(times(1));
ImageUtil.getImageDetail(imageUrl);
</code></pre>

<p>command.execute will call the ImageUtil.getImageDetail method during as part of its normal execution.</p>