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:
   This test is mocking out the called method on the next line, right? 
Shouldn't it be mocking out the method called at 
https://github.com/apache/incubator-mxnet/blob/96439e6e4889b9c6e2e00ad38b6d379837dc43e1/scala-package/infer/src/main/scala/org/apache/mxnet/infer/javaapi/ObjectDetector.scala#L68
   
   But on a bigger note, these tests are on a very thin translation layer with 
very general typing so the Mockito tests test very little. I'm concerned that 
(for example) in the future imageObjectDetect is updated, say, to return an 
iterable where the first and second arguments are reversed. This test wouldn't 
pick that up, but if the code was ever run in practice, ObjectDetectorOutput 
would crash with an illegal set of arguments, right?
   
   Is it possible to use real data here instead of Mockito?
   
   Generally, there's an argument on real objects vs Mocks that I'll quote: 
https://testing.googleblog.com/2013/05/testing-on-toilet-dont-overuse-mocks.html
   
   Mocks were made for situations where using real objects would be difficult, 
undesirable, or impossible, e.g. network calls.  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; and if the underlying code is changed, the test above should still run 
unchanged. As for performance, I wouldn't imagine a big impact.
   
   Let me know what you think about using a real object for these tests.

----------------------------------------------------------------
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

Reply via email to