jenkinsci / peass-ci-plugin

Jenkins plugin for peass to support performance measurement in CI
https://plugins.jenkins.io/peass-ci/
GNU Affero General Public License v3.0
4 stars 12 forks source link

ClearMockitoCaches Leads to Missing Inline Mocked Objects #217

Closed bam-hbt closed 1 year ago

bam-hbt commented 1 year ago

What feature do you want to see added?

If the class is mocked-inline, after clean up mockito caches the mocked obj will be lost.

Upstream changes

No response

DaGeRe commented 1 year ago

Thanks for the issue. I've created a test for this: https://github.com/DaGeRe/peass/commit/10b824abe79bb1bc8c85d6b77dae3ec8814177c2 and will fix this now.

DaGeRe commented 1 year ago

Starting with https://github.com/DaGeRe/peass/commit/3013ed193e6a61abe7f64099529cdc65a8142112, this should fully work. Could you test this?

bam-hbt commented 1 year ago

Thanks for fix, looks fine.

DaGeRe commented 1 year ago

To clarify this for future reference: This was about having mock initializing directly at field declaration, e.g.

public class MyTest {
  public static final Object myMock = Mockito.mock(Object.class);

  @Test
  public void doSomething(){ 
    Assert.assertEquals("asdasd", mock.toString());
  }
}

To fix this, the initialization needs to be moved to the @BeforeAll method (or, in case of a field variable, to @BeforeEach).

There is no relation to mockito-inline.