Main Content

Test custom external file adapter

Since R2022b


    A object provides functions for testing a custom external file adapter derived from the base class.




    adapterTester =,source,section) creates a object that can test an instance of an adapter derived from the base class. With this adapter tester you can test the getData method for your custom file adapter.

    Input Arguments

    expand all

    Custom file adapter, specified as an object of a class that derives from the base class.

    Example: myCustomFileAdapter

    External source file, specified as a character array.

    Example: 'Tires.xls'

    Section of the external file source, specified as a character array or string.

    Example: 'tireManufacturer'


    expand all

    This property is read-only.

    Workspace variables, specified as a containers.Map object. Simulink® populates the map object when you call the object function readFromSource. The keys to the map object are the workspace variable names..

    Object Functions

    clearClear variables from file adapter tester object
    readFromSourceTest custom file adapter by reading from source


    collapse all

    Create a object to test the getData method of an XML file adapter derived from a base class. For an example of an XML file adapter, see .

    The getData method reads data from an XML file test.xml in the following format.


    Create an instance of your file adapter.

    adapterInstance = myXMLAdapter;

    Create an instance of the file adapter tester object using the test file specified above.

    adapterTester =,...
                                                             'test.xml','XML Adapter');

    Use adapterTester to read the data from your XML file. Then, check the data in the WorkspaceVariables property.

    variables = adapterTester.WorkspaceVariables
    variables = 
      Map with properties:
        Count: 2
        KeyType: char
        ValueType: double

    Check the data in the WorkspaceVariables map object.

    ans = 
      1x2 cell array
        {"x"}  {"y"}

    Finally, clear the workspace variables.


    After clearing the variables, you can make changes to your XML file and use the same adapter to read the file again.


    Version History

    Introduced in R2022b