Write and Run Unit Tests

Start with the sample unit test to write unit tests and run them for your custom Oracle Content Management components.

Start with the Sample Unit Test

The Developer Cloud Service samples for Oracle Content Management include the following files to help you write unit tests:

  • src/test/unit: Contains the unit test for the Sample-To-Do component. This serves as a sample for writing unit tests for component JavaScript code, which includes RequireJS modules. The Mocha and Chai frameworks for JavaScript unit testing are used.

  • index.html: Runs the unit test. It loads Mocha, Chai, and the main test file, test-main.js.

  • test-main.js: Loads the unit test module, Sample-To-Do-Test, and runs the Mocha unit tests.

  • Sample-To-Do-Test.js:

    • Defines the actual tests. It loads the component source code, components/Sample-To-Do/assets/render.js, using RequireJS.

    • Tests the add(), delete(), title(), and placeholder() methods.

Write Unit Tests for Your Components

To write each of your unit tests for a custom component, follow these steps:

  1. Write a unit test similar to Sample-To-Do-Test.js.

  2. Load the test you wrote into test-main.js.

Run a Unit Test Locally

To run your unit test locally, follow these steps:

  1. Clone the Git repository locally.

  2. In a terminal window on your local machine, enter npm install.

  3. Enter npm start.

  4. Either enter npm test or open http://localhost:8085/unit/ in a browser.