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()
, andplaceholder()
methods.
-
Write Unit Tests for Your Components
To write each of your unit tests for a custom component, follow these steps:
-
Write a unit test similar to
Sample-To-Do-Test.js
. -
Load the test you wrote into
test-main.js
.
Run a Unit Test Locally
To run your unit test locally, follow these steps:
-
Clone the Git repository locally.
-
In a terminal window on your local machine, enter
npm install
. -
Enter
npm start
. -
Either enter
npm test
or openhttp://localhost:8085/unit/
in a browser.