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

 ##########
 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
   > 
   > 
[incubator-mxnet/scala-package/infer/src/main/scala/org/apache/mxnet/infer/javaapi/ObjectDetector.scala](https://github.com/apache/incubator-mxnet/blob/96439e6e4889b9c6e2e00ad38b6d379837dc43e1/scala-package/infer/src/main/scala/org/apache/mxnet/infer/javaapi/ObjectDetector.scala#L68)
   > Line 68 in 
[96439e6](/apache/incubator-mxnet/commit/96439e6e4889b9c6e2e00ad38b6d379837dc43e1)
   >  val ret = objDetector.imageObjectDetect(inputImage, Some(topK)) 
   > But on a bigger note, these tests are on a very thin translation layer so 
the Mockito tests test very little. Is it possible to use real data here 
instead of Mockito? It is possible that imageObjectDetect can be changed so as 
to be impossible to return "result" without violating any types. If so, this 
test would not be testing a true code path.
   > 
   > 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.
   
   Yes you have a valid point that it should be mocking out the next line. The 
unit tests for ```val ret = objDetector.imageObjectDetect(inputImage, 
Some(topK)) ``` (Scala code) already exist and can be found here : 
https://github.com/apache/incubator-mxnet/blob/master/scala-package/infer/src/test/scala/org/apache/mxnet/infer/ObjectDetectorSuite.scala
 
   
   
   As for using Mockito v/s real data, I would prefer using a proper 
integration test Suite, with real world data, and leave the unit tests to check 
the code paths and branches with mocked data. 
   
   The integ test for SSD in Java can be found here : 
https://github.com/apache/incubator-mxnet/blob/master/scala-package/mxnet-demo/java-demo/src/main/java/mxnet/ObjectDetection.java
 

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