- For API test, we use mocha (https://mochajs.org/) and chai (https://www.chaijs.com/)
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. Hosted on GitHub.
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
- Clone from https://github.com/oimtrust/reqresapi (choose
main
branch) - Copy Environment File with command
cp .env.example .env
and setup the value of variable in env file
For windows and mac user you can download node and install. For linux user you can install with ppa the tutorial can be found here.
After node and npm installed, we recommend you to also install yarn, the tutorial can be found here.
Before start development and running the test you need to install packages that needed for reqresapi. To install them, you need to do these step:
- Go to your reqresapi repo directory in your local machine with your favorite terminal.
- and run
yarn
in your terminal - wait, and done
- Use the
describe
function to create a group of test cases - Use the
it
function to create a test- The test created with
it
should follow the test cases created in testlink.
- The test created with
- Example:
describe('As a guest, I want to register', () => { it('Should unsuccessful register when insert invalid data', async () => { const response = await ReqresAPI.register(data.INVALID_REGISTER) assert.equal(response.status, 400) assert.containsAllKeys(response.data, ["error"]) assert.isString(response.data.error) }); it('Should successfully register using valid data', async () => { const response = await ReqresAPI.register(data.VALID_REGISTER) assert.equal(response.status, 200); assert.containsAllKeys(response.data, ["id", "token"]); assert.isNumber(response.data.id); assert.isString(response.data.token); }); });
- Use dot (
.
) to separete type file, examplelogin.data.js
andlogin.test.js
. - For scenario file, it should have
[name scenario].test.js
. - For scenario file that has more than 1 word using "-", example:
payment-bca.test.js
- All variables, files, functions names SHOULD BE DECLARED IN ENGLISH! Any Bahasa declaration will be rejected.
- Make all naming concise and clear.
-
Data If we need use data (such as input from csv, or raw data), should be created here
-
Helper If we need create function helper that can be used for steps, should be created here
-
Page Elements This folder consist of file that mention all element object from each page, example:
login.page.js
. -
Scenario All scenario files that describe what/flow of testing should be created here, example:
login.test.js
.
You can run the test by run these command in your terminal:
yarn run mocha:test