docs

Using Mock Data with the OData V2 Mock Server

Mock Data can be used when you start the development of an app as well as for testing and problem solving when the data service is not available or it requires effort to set up data services.

To switch to mock mode, set the URL parameter responderOn to true. We recommend to provide one check for this parameter in the app in a central place, for example in the model.Config object in the model folder.

// module:model/Config
sap.ui.define([], function() {
    return {
        isMock: ("true" === new URLSearchParams(window.location.search).get("responderOn"));
    }
});

To run your app with mock data, you can use the mock server. The mock server intercepts HTTP calls to the server and produces a faked output to the client. This is transparent to your data binding and the OData model you use, and feels like a real server. You start the mock server when you initialize your app as follows:

sap.ui.define([
    "model/Config",
    "sap/ui/app/Application",
    "sap/ui/core/util/MockServer"], function(ModelConfig, BaseApplication, MockServer) {
    return BaseApplication.extend("Application", {
        init : function () {
            ...
            // start mock server
            if (ModelConfig.isMock) {
                const oMockServer = new MockServer({
                    rootUri: ModelConfig.getServiceUrl();
                });
                oMockServer.simulate("model/metadata.xml", "model/");
                oMockServer.start();
            }
        }
    }
});

The mock server needs a metadata XML file that describes the data structure of your service. You can obtain this by opening the OData service root URL in a browser with the suffix “$metadata” appended. Copy the resulting XML file into the model folder of your application.

Remove any kind of link that points to internal servers.

The following two options for providing mock data exist: