-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests spying frequently called methods slow #258
Labels
Projects
Comments
Interesting discussions about mockito performance cost |
jzy3d
changed the title
Unit tests spying frequently called objects are slow
Unit tests spying frequently called objects methods slow
Apr 30, 2022
Performance improves a lot when doing "manual mocks", i.e. override the class and method to spy instead of asking Mockito generate the spy. A 30s test dropped to < 1s. Here we want to check how many time the method glDepthRange was called with which arguments : public class GLMock_DepthRange extends GL{
List<double[]> verify_glDepthRange = new ArrayList<>();
@Override
public void glDepthRange(double near_val, double far_val) {
super.glDepthRange(near_val, far_val);
double[] args = {near_val, far_val};
verify_glDepthRange.add(args);
}
public List<double[]> verify_glDepthRange() {
return verify_glDepthRange;
}
public void clear_glDepthRange() {
verify_glDepthRange.clear();
}
} And use it as follow public class TestAxisBox {
@Test
public void whenRenderAxis_DepthRangeModifiedByAxis() {
GLMock_DepthRange glMock = new GLMock_DepthRange();
// Given a surface chart with a mock GL injected for spying calls to glDepthRange
EmulGLChartFactory factory = EmulGLChartFactory.forGL(glMock);
Chart chart = factory.newChart(Quality.Advanced());
Shape surface = SampleGeom.surface();
chart.add(surface);
glMock.clear_glDepthRange();
// ----------------------------------------------
// When : render axis
chart.getView().getAxis().draw(chart.getPainter());
// ----------------------------------------------
// Then axis will update depth range
double[] configForAxis = {AxisBox.NO_OVERLAP_DEPTH_RATIO, 1};
double[] configForNothing = {0, 1};
Assert.assertTrue(Arrays.equals(glMock.verify_glDepthRange().get(0), configForAxis));
Assert.assertTrue(Arrays.equals(glMock.verify_glDepthRange().get(1), configForNothing));
}
} |
jzy3d
changed the title
Unit tests spying frequently called objects methods slow
Unit tests spying frequently called methods slow
Apr 30, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seams this occur with objects that may be called frequently (Painter, Camera, View, etc)
The text was updated successfully, but these errors were encountered: