leihou6116 commented on code in PR #38459:
URL: https://github.com/apache/arrow/pull/38459#discussion_r1376323553


##########
matlab/doc/testing_guidelines_for_the_matlab_interface_to_apache_arrow.md:
##########
@@ -0,0 +1,142 @@
+<!---
+  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.
+-->
+
+# Testing Guidelines for the MATLAB Interface to Apache Arrow  
+
+## Overview  
+
+The goal of this document is to provide helpful guidelines for testing 
functionality within the [`matlab` 
directory](https://github.com/apache/arrow/tree/main/matlab) of the 
[`apache/arrow`](https://github.com/apache/arrow) repository.  
+
+## Prerequisites  
+
+MATLAB interface has its own tests to ensure its quality. To run those tests 
locally on your machine, the following software must be installed on your 
machine:  
+
+1. [MATLAB](https://www.mathworks.com/products/get-matlab.html)
+2. [MATLAB Interface to Apache 
Arrow](https://github.com/mathworks/arrow/tree/main/matlab)
+
+## General Guidelines  
+
+When adding new tests, it is recommended to, at a minimum, ensure that 
real-world workflows work as expected.  
+
+If the change cannot be covered by any use case at the MATLAB interface level, 
please consider test it at the C++ level. One approach for testing C++ code is 
to create a Proxy instance manually in MATLAB and call the Proxy's method from 
a MATLAB test case. Examples can be found in 
`matlab/test/arrow/tabular/tTabularInternal.m`.
+
+### MATLAB Class-Based Unit Testing Framework  
+
+All tests for the MATLAB interface should use the [MATLAB Class-Based Unit 
Testing 
Framework](https://www.mathworks.com/help/matlab/class-based-unit-tests.html) 
(i.e. they should use 
[`matlab.unittest.TestCase`](https://www.mathworks.com/help/matlab/ref/matlab.unittest.testcase-class.html)).
  
+
+## Code Coverage Goals  
+
+When making changes to the MATLAB interface, please do your best to add tests 
to cover all changed lines, conditions, and decisions.  
+
+Before making a pull request, please check the code coverage for any changed 
code. If possible, it can be helpful to explicitly comment on the code coverage 
in your pull request description.  
+
+Although we strive for high code coverage, it is understood that some code 
cannot be reasonably tested (e.g. an "un-reachable" branch in a `switch` 
condition on an enumeration value).
+
+### How to Check Code Coverage  
+
+To generate a MATLAB code coverage report, the 
[`ReportCoverageFor`](https://www.mathworks.com/help/matlab/ref/runtests.html#mw_764c9db7-6823-439f-a77d-7fd25a03d20e)
 name-value pair argument can be supplied to the 
[`runtests`](https://www.mathworks.com/help/matlab/ref/runtests.html) command. 
Before generating the code coverage report, remember to add your source file 
directory to path. Here are the commands.
+
+```matlab  
+>> addpath( genpath(<your local arrow/matlab>) ) % Include subdirectories
+>> runtests(testFilePath/testFolderPath, 'ReportCoverageFor', 
sourceFilePath/sourceFolderPath, 'IncludeSubfolders', true/false);  
+```
+
+Below is an example of running all tests under `matlab/test` and getting the 
MATLAB code coverage report for all files under `matlab/src/matlab`.
+
+```matlab  
+>> addpath(genpath("C:\TryCodeCoverage\arrow\matlab"))
+>> runtests('C:\TryCodeCoverage\arrow\matlab\test', 'ReportCoverageFor', 
'C:\TryCodeCoverage\arrow\matlab\src\matlab\', 'IncludeSubfolders', true);
+```
+
+## Test Organization  
+
+All tests for the MATLAB interface are located under the `matlab/test` 
directory.  
+
+To make it easy to find the test files which correspond to specific source 
files, the MATLAB interface tests are organized using the following rules:  
+
+- Source and test directories follow an (approximately) "parallel" structure. 
For example, the test directory 
[`test/arrow/array`](https://github.com/apache/arrow/tree/main/matlab/test/arrow/array)
 contains tests for the source directory 
[`src/matlab/+arrow/+array`](https://github.com/apache/arrow/tree/main/matlab/src/matlab/%2Barrow/%2Barray).
  
+- One test file maps to one source file. For example, 
[`test/arrow/array/tArray.m`](https://github.com/apache/arrow/blob/main/matlab/test/arrow/array/tArray.m)
 is the test file for 
[`src/matlab/+arrow/+array/Array.m`](https://github.com/apache/arrow/blob/main/matlab/src/matlab/%2Barrow/%2Barray/Array.m).
  
+- **Note**: In certain scenarios, it can make sense to diverge from these 
rules. For example, if a particular class is very complex and contains a lot of 
divergent functionality (which we generally try to avoid), we might choose to 
split the testing into several "focused" test files (e.g. one for testing the 
class display, one for testing the properties, and one for testing the 
methods).  
+
+## Continuous Integration (CI) Workflows  
+
+The Apache Arrow project uses [GitHub 
Actions](https://github.com/features/actions) as its primary [Continuous 
Integration (CI)](https://en.wikipedia.org/wiki/Continuous_integration) 
platform.  
+
+Creating a pull request that changes code in the MATLAB interface will 
automatically trigger [MATLAB CI 
Workflows](https://github.com/apache/arrow/actions/workflows/matlab.yml) to be 
run. These CI workflows will run all tests located under the `matlab/test` 
directory.  
+
+Reviewers will generally expect the MATLAB CI Workflows to be passing 
successfully before they will consider merging a pull request.  
+
+If you are having trouble understanding CI failures, you can always ask a 
reviewer or another community member for help.  
+
+## Writing Tests  
+
+Tests for MATLAB interface should use the MATLAB testing framework 
[`matlab.unittest.TestCase 
class`](https://www.mathworks.com/help/matlab/ref/matlab.unittest.testcase-class.html).
 Here is a simple example.  

Review Comment:
   I took Sarah's review feedback. I combined "Writing Tests" and "MATLAB 
Class-Based Unit Testing Framework".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to