vishaalkapoor commented on a change in pull request #13794: [MXNET-1263] Unit Tests for Java Predictor and Object Detector APIs URL: https://github.com/apache/incubator-mxnet/pull/13794#discussion_r246145763
########## File path: scala-package/infer/src/test/java/org/apache/mxnet/infer/javaapi/ObjectDetectorTest.java ########## @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.mxnet.infer.javaapi; + +import org.apache.mxnet.Layout; +import org.apache.mxnet.javaapi.DType; +import org.apache.mxnet.javaapi.DataDesc; +import org.apache.mxnet.javaapi.NDArray; +import org.apache.mxnet.javaapi.Shape; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + +public class ObjectDetectorTest { + + List<DataDesc> inputDesc; + BufferedImage inputImage; + + List<List<ObjectDetectorOutput>> result; + + ObjectDetector objectDetector; + + @Before + public void setUp() { + + inputDesc = new ArrayList<>(); + inputDesc.add(new DataDesc("", new Shape(new int[]{1, 3, 512, 512}), DType.Float32(), Layout.NCHW())); + inputImage = new BufferedImage(512, 512, BufferedImage.TYPE_INT_RGB); + objectDetector = Mockito.mock(ObjectDetector.class); + result = new ArrayList<>(); + result.add(new ArrayList<ObjectDetectorOutput>()); + result.get(0).add(new ObjectDetectorOutput("simbaa", new float[]{})); + } + + @Test + public void testObjectDetectorWithInputImage() { + + Mockito.when(objectDetector.imageObjectDetect(inputImage, 5)).thenReturn(result); + List<List<ObjectDetectorOutput>> actualResult = objectDetector.imageObjectDetect(inputImage, 5); Review comment: Is it possible to use real data here instead of Mockito? Mockito was made for situations where real objects would be difficult or impossible. This seems like a situation where we can use a real object and test code paths. I do realize there is an argument that if you use a real object, you're not isolating the component your testing, but on the flip side, using a mock is not as likely to catch real errors. There is an argument in favor of preferring real objects to mocks here if you're curious: https://testing.googleblog.com/2013/05/testing-on-toilet-dont-overuse-mocks.html ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
